File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,11 @@ function Start-Htmx {
107107 [ScriptBlock ]
108108 $Handler ,
109109
110+ # The lifespan of the server. After this time, the server will stop.
111+ [Parameter (ValueFromPipelineByPropertyName )]
112+ [timespan ]
113+ $LifeSpan ,
114+
110115 # The name of the palette to use. This will include the [4bitcss](https://4bitcss.com) stylesheet.
111116 [Alias (' Palette' , ' ColorScheme' , ' ColorPalette' )]
112117 [ArgumentCompleter ({
@@ -156,6 +161,7 @@ function Start-Htmx {
156161 $ExecutionContext.SessionState.PSVariable.Set ($keyValuePair.Key , $keyValuePair.Value )
157162 }
158163 # Start the listener
164+ $ServerStartTime = [DateTime ]::Now
159165 $httpListener.Start ()
160166 # If we have routes, we will cache all of their possible parameters now
161167 if ($route.Count ) {
@@ -179,6 +185,16 @@ function Start-Htmx {
179185 # While the server is listening
180186 while ($httpListener.IsListening ) {
181187 try {
188+ # If the server has a lifespan, we will stop it after the lifespan has passed.
189+ if (
190+ $LifeSpan -is [timespan ] -and
191+ $lifeSpan.TotalMilliseconds -and
192+ [DateTime ]::Now -gt $ServerStartTime.Add ($LifeSpan )
193+ ) {
194+ $httpListener.Stop ()
195+ break
196+ }
197+
182198 # Try to get a the next context
183199 $contextAsync = $httpListener.GetContextAsync ()
184200 $context = $contextAsync.Result
You can’t perform that action at this time.
0 commit comments