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.
This commit is contained in:
Nayeem Rahman 2020-03-10 19:14:22 +00:00 committed by GitHub
parent 8078d976d2
commit 55119aaee2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 56 deletions

View file

@ -1522,7 +1522,7 @@ declare namespace Deno {
/** **UNSTABLE**: new API, yet to be vetted.
*
* A generic transport listener for message-oriented protocols. */
export interface UDPConn extends AsyncIterator<[Uint8Array, Addr]> {
export interface UDPConn extends AsyncIterable<[Uint8Array, Addr]> {
/** **UNSTABLE**: new API, yet to be vetted.
*
* Waits for and resolves to the next message to the `UDPConn`. */
@ -1542,7 +1542,7 @@ declare namespace Deno {
}
/** A generic network listener for stream-oriented protocols. */
export interface Listener extends AsyncIterator<Conn> {
export interface Listener extends AsyncIterable<Conn> {
/** Waits for and resolves to the next connection to the `Listener`. */
accept(): Promise<Conn>;
/** Close closes the listener. Any pending accept promises will be rejected