File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,11 @@ function Start-Htmx {
107
107
[ScriptBlock ]
108
108
$Handler ,
109
109
110
+ # The lifespan of the server. After this time, the server will stop.
111
+ [Parameter (ValueFromPipelineByPropertyName )]
112
+ [timespan ]
113
+ $LifeSpan ,
114
+
110
115
# The name of the palette to use. This will include the [4bitcss](https://4bitcss.com) stylesheet.
111
116
[Alias (' Palette' , ' ColorScheme' , ' ColorPalette' )]
112
117
[ArgumentCompleter ({
@@ -156,6 +161,7 @@ function Start-Htmx {
156
161
$ExecutionContext.SessionState.PSVariable.Set ($keyValuePair.Key , $keyValuePair.Value )
157
162
}
158
163
# Start the listener
164
+ $ServerStartTime = [DateTime ]::Now
159
165
$httpListener.Start ()
160
166
# If we have routes, we will cache all of their possible parameters now
161
167
if ($route.Count ) {
@@ -179,6 +185,16 @@ function Start-Htmx {
179
185
# While the server is listening
180
186
while ($httpListener.IsListening ) {
181
187
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
+
182
198
# Try to get a the next context
183
199
$contextAsync = $httpListener.GetContextAsync ()
184
200
$context = $contextAsync.Result
You can’t perform that action at this time.
0 commit comments