feat: disposable Deno resources (#20845)

This commit implements Symbol.dispose and Symbol.asyncDispose for
the relevant resources.

Closes #20839

---------

Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Luca Casonato 2023-11-01 20:26:12 +01:00 committed by GitHub
parent 1d19b1011b
commit d42f154312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 342 additions and 35 deletions

View file

@ -2,6 +2,7 @@
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
/// <reference lib="esnext.disposable" />
declare namespace Deno {
/** @category Network */
@ -24,7 +25,8 @@ declare namespace Deno {
*
* @category Network
*/
export interface Listener<T extends Conn = Conn> extends AsyncIterable<T> {
export interface Listener<T extends Conn = Conn>
extends AsyncIterable<T>, Disposable {
/** Waits for and resolves to the next connection to the `Listener`. */
accept(): Promise<T>;
/** Close closes the listener. Any pending accept promises will be rejected
@ -57,7 +59,7 @@ declare namespace Deno {
export type TlsListener = Listener<TlsConn>;
/** @category Network */
export interface Conn extends Reader, Writer, Closer {
export interface Conn extends Reader, Writer, Closer, Disposable {
/** The local address of the connection. */
readonly localAddr: Addr;
/** The remote address of the connection. */