From 55119aaee2e5fec8074373ef51b56d5095da1faf Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 10 Mar 2020 19:14:22 +0000 Subject: 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. --- std/http/server.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'std') 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 { ): AsyncIterableIterator { 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. -- cgit v1.2.3