First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
/**
* An object that provides an async `.dispose()` method that can called only once.
*
* Calling `.dispose()` will call the provided `onDispose` function only once.
* Any subsequent calls to `.dispose()` will do nothing.
*/
export class AsyncDisposableHandle {
/** @internal */ _onDispose;
/** @internal */ _disposePromise;
constructor(onDispose) {
this._onDispose = onDispose;
this.dispose = this.dispose.bind(this);
this[Symbol.asyncDispose] = this[Symbol.asyncDispose].bind(this);
}
get disposed() {
return this._onDispose == null;
}
async [Symbol.asyncDispose]() {
await this.dispose();
}
async dispose() {
if (this._onDispose != null) {
const onDispose = this._onDispose;
delete this._onDispose;
this._disposePromise = onDispose();
await this._disposePromise;
}
await this._disposePromise;
}
}
//# sourceMappingURL=AsyncDisposableHandle.js.map