summaryrefslogtreecommitdiff
path: root/std/http/server.ts
diff options
context:
space:
mode:
authorNayeem Rahman <muhammed.9939@gmail.com>2020-03-10 19:14:22 +0000
committerGitHub <noreply@github.com>2020-03-10 15:14:22 -0400
commit55119aaee2e5fec8074373ef51b56d5095da1faf (patch)
treec1ad9bc7526ffa0941df4c552e0ddf113beac9df /std/http/server.ts
parent8078d976d29aa12819e3f5a781c846d67868b0d6 (diff)
refactor(cli/js/net): Cleanup iterable APIs (#4236)
Listener and UDPConn are AsyncIterables instead of AsyncIterators. The [Symbol.asyncIterator]()s are defined as generators and the next() methods are gone. "Listener/Socket has been closed" errors are now BadResource.
Diffstat (limited to 'std/http/server.ts')
-rw-r--r--std/http/server.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/std/http/server.ts b/std/http/server.ts
index 6e26e8456..d7ed60c53 100644
--- a/std/http/server.ts
+++ b/std/http/server.ts
@@ -198,9 +198,15 @@ export class Server implements AsyncIterable<ServerRequest> {
): AsyncIterableIterator<ServerRequest> {
if (this.closing) return;
// Wait for a new connection.
- const { value, done } = await this.listener.next();
- if (done) return;
- const conn = value as Conn;
+ let conn: Conn;
+ try {
+ conn = await this.listener.accept();
+ } catch (error) {
+ if (error instanceof Deno.errors.BadResource) {
+ return;
+ }
+ throw error;
+ }
// Try to accept another connection and add it to the multiplexer.
mux.add(this.acceptConnAndIterateHttpRequests(mux));
// Yield the requests that arrive on the just-accepted connection.