From d42f1543121e7245789a96a485d1ef7645cb5fba Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 1 Nov 2023 20:26:12 +0100 Subject: feat: disposable Deno resources (#20845) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit implements Symbol.dispose and Symbol.asyncDispose for the relevant resources. Closes #20839 --------- Signed-off-by: Bartek Iwańczuk Co-authored-by: Bartek Iwańczuk --- cli/tsc/99_main_compiler.js | 6 +++++- cli/tsc/dts/lib.deno.ns.d.ts | 16 +++++++++++----- cli/tsc/dts/lib.deno.unstable.d.ts | 4 +++- 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'cli/tsc') diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index e246d5d0c..a2079c01e 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -1138,6 +1138,7 @@ delete Object.prototype.__proto__; `${ASSETS_URL_PREFIX}${specifier}`, ts.ScriptTarget.ESNext, ), + `failed to load '${ASSETS_URL_PREFIX}${specifier}'`, ); } // this helps ensure as much as possible is in memory that is re-usable @@ -1148,7 +1149,10 @@ delete Object.prototype.__proto__; options: SNAPSHOT_COMPILE_OPTIONS, host, }); - assert(ts.getPreEmitDiagnostics(TS_SNAPSHOT_PROGRAM).length === 0); + assert( + ts.getPreEmitDiagnostics(TS_SNAPSHOT_PROGRAM).length === 0, + "lib.d.ts files have errors", + ); // remove this now that we don't need it anymore for warming up tsc sourceFileCache.delete(buildSpecifier); diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index e51e9736a..08c8e9e9d 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -2,6 +2,7 @@ /// /// +/// /// /** Deno provides extra properties on `import.meta`. These are included here @@ -2177,7 +2178,8 @@ declare namespace Deno { WriterSync, Seeker, SeekerSync, - Closer { + Closer, + Disposable { /** The resource ID associated with the file instance. The resource ID * should be considered an opaque reference to resource. */ readonly rid: number; @@ -2451,6 +2453,8 @@ declare namespace Deno { * ``` */ close(): void; + + [Symbol.dispose](): void; } /** @@ -3831,7 +3835,7 @@ declare namespace Deno { * * @category File System */ - export interface FsWatcher extends AsyncIterable { + export interface FsWatcher extends AsyncIterable, Disposable { /** The resource id. */ readonly rid: number; /** Stops watching the file system and closes the watcher resource. */ @@ -4284,7 +4288,7 @@ declare namespace Deno { * * @category Sub Process */ - export class ChildProcess { + export class ChildProcess implements Disposable { get stdin(): WritableStream; get stdout(): ReadableStream; get stderr(): ReadableStream; @@ -4307,6 +4311,8 @@ declare namespace Deno { /** Ensure that the status of the child process does not block the Deno * process from exiting. */ unref(): void; + + [Symbol.dispose](): void; } /** @@ -5258,7 +5264,7 @@ declare namespace Deno { * requests on the HTTP server connection. * * @category HTTP Server */ - export interface HttpConn extends AsyncIterable { + export interface HttpConn extends AsyncIterable, Disposable { /** The resource ID associated with this connection. Generally users do not * need to be aware of this identifier. */ readonly rid: number; @@ -5911,7 +5917,7 @@ declare namespace Deno { * * @category HTTP Server */ - export interface HttpServer { + export interface HttpServer extends AsyncDisposable { /** A promise that resolves once server finishes - eg. when aborted using * the signal passed to {@linkcode ServeOptions.signal}. */ diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index c758e620c..3bdba510b 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -1749,7 +1749,7 @@ declare namespace Deno { * * @category KV */ - export class Kv { + export class Kv implements Disposable { /** * Retrieve the value and versionstamp for the given key from the database * in the form of a {@linkcode Deno.KvEntryMaybe}. If no value exists for @@ -1945,6 +1945,8 @@ declare namespace Deno { * operations immediately. */ close(): void; + + [Symbol.dispose](): void; } /** **UNSTABLE**: New API, yet to be vetted. -- cgit v1.2.3