Skip to content

Commit

Permalink
fix(ext/http): Deno.Server should not be thenable (denoland#20723)
Browse files Browse the repository at this point in the history
Otherwise you can not return `Deno.Server` from async functions.

Co-authored-by: Yoshiya Hinosawa <[email protected]>
Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
3 people committed Oct 9, 2023
1 parent 35f028d commit ae81065
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 11 additions & 0 deletions cli/tests/unit/serve_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 0 additions & 6 deletions ext/http/00_serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ae81065

Please sign in to comment.