Skip to content

Commit

Permalink
fix(ext/http): Deno.Server should not be thenable
Browse files Browse the repository at this point in the history
Otherwise you can not return `Deno.Server` from async functions.
  • Loading branch information
lucacasonato committed Sep 28, 2023
1 parent 35fad4d commit 8564d36
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 @@ -3715,3 +3715,14 @@ async function curlRequestWithStdErr(args: string[]) {
assert(success);
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 });
assert(!("then" in server));
return server;
}
const server = await serveTest();
server.close();
});
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, TcpConn } from "ext:deno_net/01_net.js";
import { listenTls } from "ext:deno_net/02_tls.js";
const {
ArrayPrototypePush,
Error,
ObjectPrototypeIsPrototypeOf,
PromisePrototypeCatch,
Symbol,
Expand Down Expand Up @@ -664,11 +663,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 8564d36

Please sign in to comment.