diff --git a/docs/runtime/http_server_apis.md b/docs/runtime/http_server_apis.md index b9a64a272d..9880b542a6 100644 --- a/docs/runtime/http_server_apis.md +++ b/docs/runtime/http_server_apis.md @@ -74,10 +74,10 @@ There is also the `.accept()` method on the listener which can be used: const server = Deno.listen({ port: 8080 }); while (true) { - const conn = server.accept(); - if (conn) { + try { + const conn = await server.accept(); // ... handle the connection ... - } else { + } catch (err) { // The listener has closed break; } @@ -122,8 +122,8 @@ await the next request. It would look something like this: const server = Deno.listen({ port: 8080 }); while (true) { - const conn = server.accept(); - if (conn) { + try { + const conn = await server.accept(); (async () => { const httpConn = Deno.serveHttp(conn); while (true) { @@ -136,7 +136,7 @@ while (true) { } } })(); - } else { + } catch (err) { // The listener has closed break; }