@whatwg-node/disposablestack
Advanced tools
Comparing version 0.0.1 to 0.0.2-rc-20240821205836-a75eca740055dd912dde456b68e86737ad95c8c9
@@ -9,3 +9,3 @@ "use strict"; | ||
get disposed() { | ||
return false; | ||
return this.callbacks.length === 0; | ||
} | ||
@@ -37,9 +37,40 @@ use(value) { | ||
} | ||
async [symbols_js_1.DisposableSymbols.asyncDispose]() { | ||
for (const cb of this.callbacks) { | ||
await cb(); | ||
_error; | ||
_iterateCallbacks() { | ||
try { | ||
const cb = this.callbacks.pop(); | ||
if (cb) { | ||
const res$ = cb(); | ||
if (res$?.then) { | ||
return res$.then(() => this._iterateCallbacks(), error => { | ||
this._error = this._error ? new SuppressedError(error, this._error) : error; | ||
return this._iterateCallbacks(); | ||
}); | ||
} | ||
} | ||
} | ||
catch (error) { | ||
this._error = this._error ? new SuppressedError(error, this._error) : error; | ||
} | ||
finally { | ||
// eslint-disable-next-line no-unsafe-finally | ||
return this._iterateCallbacks(); | ||
} | ||
} | ||
[symbols_js_1.DisposableSymbols.asyncDispose]() { | ||
const res$ = this._iterateCallbacks(); | ||
if (res$?.then) { | ||
return res$.then(() => { | ||
if (this._error) { | ||
throw this._error; | ||
} | ||
}); | ||
} | ||
if (this._error) { | ||
throw this._error; | ||
} | ||
return undefined; | ||
} | ||
[Symbol.toStringTag] = 'AsyncDisposableStack'; | ||
} | ||
exports.PonyfillAsyncDisposableStack = PonyfillAsyncDisposableStack; |
@@ -9,7 +9,4 @@ "use strict"; | ||
get disposed() { | ||
return false; | ||
return this.callbacks.length === 0; | ||
} | ||
dispose() { | ||
return this[symbols_js_1.DisposableSymbols.dispose](); | ||
} | ||
use(value) { | ||
@@ -34,10 +31,17 @@ if ((0, utils_js_1.isSyncDisposable)(value)) { | ||
} | ||
[symbols_js_1.DisposableSymbols.dispose]() { | ||
for (const cb of this.callbacks) { | ||
dispose() { | ||
return this[symbols_js_1.DisposableSymbols.dispose](); | ||
} | ||
_iterateCallbacks() { | ||
const cb = this.callbacks.pop(); | ||
if (cb) { | ||
cb(); | ||
return this._iterateCallbacks(); | ||
} | ||
this.callbacks = []; | ||
} | ||
[symbols_js_1.DisposableSymbols.dispose]() { | ||
return this._iterateCallbacks(); | ||
} | ||
[Symbol.toStringTag] = 'DisposableStack'; | ||
} | ||
exports.PonyfillDisposableStack = PonyfillDisposableStack; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AsyncDisposableStack = exports.DisposableStack = void 0; | ||
exports.SuppressedError = exports.AsyncDisposableStack = exports.DisposableStack = void 0; | ||
const tslib_1 = require("tslib"); | ||
const AsyncDisposableStack_js_1 = require("./AsyncDisposableStack.js"); | ||
const DisposableStack_js_1 = require("./DisposableStack.js"); | ||
const SupressedError_js_1 = require("./SupressedError.js"); | ||
exports.DisposableStack = globalThis.DisposableStack || DisposableStack_js_1.PonyfillDisposableStack; | ||
exports.AsyncDisposableStack = globalThis.AsyncDisposableStack || AsyncDisposableStack_js_1.PonyfillAsyncDisposableStack; | ||
exports.SuppressedError = globalThis.SuppressedError || SupressedError_js_1.PonyfillSuppressedError; | ||
tslib_1.__exportStar(require("./symbols.js"), exports); |
@@ -6,3 +6,3 @@ import { DisposableSymbols } from './symbols.js'; | ||
get disposed() { | ||
return false; | ||
return this.callbacks.length === 0; | ||
} | ||
@@ -34,8 +34,39 @@ use(value) { | ||
} | ||
async [DisposableSymbols.asyncDispose]() { | ||
for (const cb of this.callbacks) { | ||
await cb(); | ||
_error; | ||
_iterateCallbacks() { | ||
try { | ||
const cb = this.callbacks.pop(); | ||
if (cb) { | ||
const res$ = cb(); | ||
if (res$?.then) { | ||
return res$.then(() => this._iterateCallbacks(), error => { | ||
this._error = this._error ? new SuppressedError(error, this._error) : error; | ||
return this._iterateCallbacks(); | ||
}); | ||
} | ||
} | ||
} | ||
catch (error) { | ||
this._error = this._error ? new SuppressedError(error, this._error) : error; | ||
} | ||
finally { | ||
// eslint-disable-next-line no-unsafe-finally | ||
return this._iterateCallbacks(); | ||
} | ||
} | ||
[DisposableSymbols.asyncDispose]() { | ||
const res$ = this._iterateCallbacks(); | ||
if (res$?.then) { | ||
return res$.then(() => { | ||
if (this._error) { | ||
throw this._error; | ||
} | ||
}); | ||
} | ||
if (this._error) { | ||
throw this._error; | ||
} | ||
return undefined; | ||
} | ||
[Symbol.toStringTag] = 'AsyncDisposableStack'; | ||
} |
@@ -6,7 +6,4 @@ import { DisposableSymbols } from './symbols.js'; | ||
get disposed() { | ||
return false; | ||
return this.callbacks.length === 0; | ||
} | ||
dispose() { | ||
return this[DisposableSymbols.dispose](); | ||
} | ||
use(value) { | ||
@@ -31,9 +28,16 @@ if (isSyncDisposable(value)) { | ||
} | ||
[DisposableSymbols.dispose]() { | ||
for (const cb of this.callbacks) { | ||
dispose() { | ||
return this[DisposableSymbols.dispose](); | ||
} | ||
_iterateCallbacks() { | ||
const cb = this.callbacks.pop(); | ||
if (cb) { | ||
cb(); | ||
return this._iterateCallbacks(); | ||
} | ||
this.callbacks = []; | ||
} | ||
[DisposableSymbols.dispose]() { | ||
return this._iterateCallbacks(); | ||
} | ||
[Symbol.toStringTag] = 'DisposableStack'; | ||
} |
import { PonyfillAsyncDisposableStack } from './AsyncDisposableStack.js'; | ||
import { PonyfillDisposableStack } from './DisposableStack.js'; | ||
import { PonyfillSuppressedError } from './SupressedError.js'; | ||
export const DisposableStack = globalThis.DisposableStack || PonyfillDisposableStack; | ||
export const AsyncDisposableStack = globalThis.AsyncDisposableStack || PonyfillAsyncDisposableStack; | ||
export const SuppressedError = globalThis.SuppressedError || PonyfillSuppressedError; | ||
export * from './symbols.js'; |
{ | ||
"name": "@whatwg-node/disposablestack", | ||
"version": "0.0.1", | ||
"version": "0.0.2-rc-20240821205836-a75eca740055dd912dde456b68e86737ad95c8c9", | ||
"description": "Cross Platform Smart DisposableStack API Ponyfill", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
@@ -11,4 +11,6 @@ import { DisposableSymbols } from './symbols.js'; | ||
disposeAsync(): Promise<void>; | ||
private _error?; | ||
private _iterateCallbacks; | ||
[DisposableSymbols.asyncDispose](): Promise<void>; | ||
readonly [Symbol.toStringTag]: string; | ||
} |
@@ -5,3 +5,2 @@ import { DisposableSymbols } from './symbols.js'; | ||
get disposed(): boolean; | ||
dispose(): void; | ||
use<T extends Disposable | null | undefined>(value: T): T; | ||
@@ -11,4 +10,6 @@ adopt<T>(value: T, onDispose: (value: T) => void): T; | ||
move(): DisposableStack; | ||
dispose(): void; | ||
private _iterateCallbacks; | ||
[DisposableSymbols.dispose](): void; | ||
readonly [Symbol.toStringTag]: string; | ||
} |
export declare const DisposableStack: DisposableStackConstructor; | ||
export declare const AsyncDisposableStack: AsyncDisposableStackConstructor; | ||
export declare const SuppressedError: SuppressedErrorConstructor; | ||
export * from './symbols.js'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
16270
26
375