AsyncDisposableStack Class
Package: @esfx/disposable
A container for asynchronously disposable resources. When the stack is disposed, its containing resources are disposed in the reverse of the order in which they were added.
Declaration
export declare class AsyncDisposableStack implements AsyncDisposable
Constructors
constructor()
Constructs a new instance of the AsyncDisposableStack
class
Declaration
constructor();
Properties
[Symbol.toStringTag]
Declaration
[Symbol.toStringTag]: string;
Property Value
disposed
Gets a value indicating whether the stack has already been disposed.
Declaration
get disposed(): boolean;
Property Value
Methods
[AsyncDisposable.asyncDispose]()
Dispose this object's resources.
Declaration
[AsyncDisposable.asyncDispose](): Promise<void>;
Returns
adopt(value, onDisposeAsync)
Pushes a non-disposable resource onto the stack with the provided async disposal callback.
Declaration
adopt<T>(value: T, onDisposeAsync: (value: T) => void | PromiseLike<void>): T;
Type Parameters
- T
Parameters
- value
- T
The resource to add.
- onDisposeAsync
- (value: T) => void | PromiseLike<void>
The callback to execute when the resource is disposed.
Returns
The resource provided.
defer(onDisposeAsync)
Pushes a resourceless async disposal callback onto the stack.
Declaration
defer(onDisposeAsync: () => void | PromiseLike<void>): void;
Parameters
Returns
disposeAsync()
Dispose this object's resources. This method is an alias for [Disposable.dispose]()
.
const stack = new AsyncDisposableStack();
for (const f of files) stack.use(openFile(f));
...
await stack.disposeAsync();
Declaration
disposeAsync(): Promise<void>;
Returns
move()
Moves all resources out of this AsyncDisposableStack
and into a new AsyncDisposableStack
and returns it.
Declaration
move(): AsyncDisposableStack;
Returns
use(value)
Pushes a new disposable resource onto the disposable stack stack. Resources are disposed in the reverse order they were entered.
Declaration
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
Type Parameters
- T
Parameters
- value
- T
The resource to add.
Returns
The resource provided.