summaryrefslogtreecommitdiff
path: root/js/net.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/net.ts')
-rw-r--r--js/net.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/js/net.ts b/js/net.ts
index 214da2927..7bf6dc098 100644
--- a/js/net.ts
+++ b/js/net.ts
@@ -14,7 +14,7 @@ export type Network = "tcp";
export type Addr = string;
/** A Listener is a generic network listener for stream-oriented protocols. */
-export interface Listener {
+export interface Listener extends AsyncIterator<Conn> {
/** Waits for and resolves to the next connection to the `Listener`. */
accept(): Promise<Conn>;
@@ -25,6 +25,8 @@ export interface Listener {
/** Return the address of the `Listener`. */
addr(): Addr;
+
+ [Symbol.asyncIterator](): AsyncIterator<Conn>;
}
enum ShutdownMode {
@@ -97,6 +99,17 @@ class ListenerImpl implements Listener {
addr(): Addr {
return notImplemented();
}
+
+ async next(): Promise<IteratorResult<Conn>> {
+ return {
+ done: false,
+ value: await this.accept()
+ };
+ }
+
+ [Symbol.asyncIterator](): AsyncIterator<Conn> {
+ return this;
+ }
}
export interface Conn extends Reader, Writer, Closer {