Skip to content

Commit 53404f1

Browse files
author
Junhui Tong
committedJul 17, 2024
fix exit slowly
1 parent df54281 commit 53404f1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed
 

‎dwa/dwa_service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as enc from 'jsr:@std/encoding@1.0.1'
55

66
const clients: WebSocket[] = []
77
let server: Deno.HttpServer | null = null
8+
const ac = new AbortController()
89
export function startDenoWebAppService(root: string, port: number, apiImpl: {[key: string]: Function}) {
910
const handlerCORS = async (req: Request) => {
1011
// handle websocket connection
@@ -37,7 +38,7 @@ export function startDenoWebAppService(root: string, port: number, apiImpl: {[ke
3738
setTimeout(() => {
3839
if (clients.length === 0) {
3940
console.log('no more clients, shutting down server')
40-
server?.shutdown()
41+
ac.abort()
4142
}
4243
}, 2000)
4344
}
@@ -83,10 +84,10 @@ export function startDenoWebAppService(root: string, port: number, apiImpl: {[ke
8384
}
8485
};
8586

86-
server = Deno.serve({ port }, handlerCORS);
87+
server = Deno.serve({ port, signal:ac.signal }, handlerCORS);
8788
return server
8889
}
8990

9091
export function stopDenoWebAppService() {
91-
server?.shutdown()
92+
ac.abort()
9293
}

‎ev.ps1

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
Invoke-RestMethod https://deno.land/install.ps1 | Invoke-Expression
1+
if (!(Get-Command deno -ErrorAction SilentlyContinue)) {
2+
Write-Output "Deno is not installed. Installing Deno..."
3+
Invoke-RestMethod https://deno.land/install.ps1 | Invoke-Expression
4+
}
25
deno run -A jsr:@timepp/ev

0 commit comments

Comments
 (0)
Please sign in to comment.