diff options
| author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-11-11 05:41:52 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-11 19:11:52 +0530 |
| commit | ff92febb385c166744b49219ca7b3059c41ad34a (patch) | |
| tree | 90c4c6e134a295906e693e8821f609bfc76cfa67 /ext/flash/01_http.js | |
| parent | 5be8c96ae899f5944da70e1909da7e608afefafa (diff) | |
fix(ext/flash): graceful server startup/shutdown (#16383)
Fixes https://github.com/denoland/deno/issues/16267
Co-authored-by: Yusuke Tanaka <yusuktan@maguro.dev>
Diffstat (limited to 'ext/flash/01_http.js')
| -rw-r--r-- | ext/flash/01_http.js | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js index 7a6b9bc47..8eed6047e 100644 --- a/ext/flash/01_http.js +++ b/ext/flash/01_http.js @@ -188,8 +188,8 @@ return str; } - function prepareFastCalls() { - return core.ops.op_flash_make_request(); + function prepareFastCalls(serverId) { + return core.ops.op_flash_make_request(serverId); } function hostnameForDisplay(hostname) { @@ -482,15 +482,11 @@ const serverId = opFn(listenOpts); const serverPromise = core.opAsync("op_flash_drive_server", serverId); - - PromisePrototypeCatch( - PromisePrototypeThen( - core.opAsync("op_flash_wait_for_listening", serverId), - (port) => { - onListen({ hostname: listenOpts.hostname, port }); - }, - ), - () => {}, + const listenPromise = PromisePrototypeThen( + core.opAsync("op_flash_wait_for_listening", serverId), + (port) => { + onListen({ hostname: listenOpts.hostname, port }); + }, ); const finishedPromise = PromisePrototypeCatch(serverPromise, () => {}); @@ -506,7 +502,7 @@ return; } server.closed = true; - await core.opAsync("op_flash_close_server", serverId); + core.ops.op_flash_close_server(serverId); await server.finished; }, async serve() { @@ -618,7 +614,7 @@ signal?.addEventListener("abort", () => { clearInterval(dateInterval); - PromisePrototypeThen(server.close(), () => {}, () => {}); + server.close(); }, { once: true, }); @@ -633,7 +629,7 @@ ); } - const fastOp = prepareFastCalls(); + const fastOp = prepareFastCalls(serverId); let nextRequestSync = () => fastOp.nextRequest(); let getMethodSync = (token) => fastOp.getMethod(token); let respondFast = (token, response, shutdown) => @@ -653,8 +649,8 @@ } await SafePromiseAll([ + listenPromise, PromisePrototypeCatch(server.serve(), console.error), - serverPromise, ]); }; } |
