diff options
author | Luca Casonato <hello@lcas.dev> | 2023-10-09 12:43:14 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-09 12:43:14 +0900 |
commit | ae81065c758a540aa61639e51372c1e254d92c9a (patch) | |
tree | 0012576dc0cce32460c0bbab99d615ea80846c5a | |
parent | 35f028daf27bb40e86829e7b7cc19aa72a62c0a0 (diff) |
fix(ext/http): Deno.Server should not be thenable (#20723)
Otherwise you can not return `Deno.Server` from async functions.
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
-rw-r--r-- | cli/tests/unit/serve_test.ts | 11 | ||||
-rw-r--r-- | ext/http/00_serve.js | 6 |
2 files changed, 11 insertions, 6 deletions
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts index 6f58db006..2e560af99 100644 --- a/cli/tests/unit/serve_test.ts +++ b/cli/tests/unit/serve_test.ts @@ -3717,6 +3717,17 @@ async function curlRequestWithStdErr(args: string[]) { return [new TextDecoder().decode(stdout), new TextDecoder().decode(stderr)]; } +Deno.test("Deno.Server is not thenable", async () => { + // deno-lint-ignore require-await + async function serveTest() { + const server = Deno.serve({ port: servePort }, (_) => new Response("")); + assert(!("then" in server)); + return server; + } + const server = await serveTest(); + await server.shutdown(); +}); + Deno.test( { ignore: Deno.build.os === "windows", diff --git a/ext/http/00_serve.js b/ext/http/00_serve.js index e74e1e71f..2e0c62fef 100644 --- a/ext/http/00_serve.js +++ b/ext/http/00_serve.js @@ -38,7 +38,6 @@ import { listen, listenOptionApiName, TcpConn } from "ext:deno_net/01_net.js"; import { listenTls } from "ext:deno_net/02_tls.js"; const { ArrayPrototypePush, - Error, ObjectHasOwn, ObjectPrototypeIsPrototypeOf, PromisePrototypeCatch, @@ -700,11 +699,6 @@ function serveHttpOn(context, callback) { context.closed = true; } }, - then() { - throw new Error( - "Deno.serve no longer returns a promise. await server.finished instead of server.", - ); - }, ref() { ref = true; if (currentPromise) { |