DisposableStack Class
Package: @esfx/disposable
A container for 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 DisposableStack
Constructors
constructor()
Creates a new DisposableStack.
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
[Disposable.dispose]()
Dispose this object's resources.
Declaration
[Disposable.dispose](): void;
Returns
adopt(value, onDispose)
Pushes a non-disposable resource onto the stack with the provided disposal callback.
Declaration
adopt<T>(value: T, onDispose: (value: T) => void): T;
Type Parameters
- T
Parameters
- value
- T
The resource to add.
- onDispose
- (value: T) => void
The callback to execute when the resource is disposed.
Returns
The resource provided.
defer(onDispose)
Pushes a resourceless disposal callback onto the stack.
Declaration
defer(onDispose: () => void): void;
Parameters
- onDispose
- () => void
The callback to execute when the stack is disposed.
Returns
dispose()
Dispose this object's resources. This method is an alias for [Disposable.dispose]()
.
const stack = new DisposableStack();
for (const f of files) stack.use(openFile(f));
...
stack.dispose();
Declaration
dispose(): void;
Returns
move()
Moves all resources out of this DisposableStack
and into a new DisposableStack
and returns it.
Declaration
move(): DisposableStack;
Returns
use(value)
Pushes a disposable resource onto the disposable stack stack. Resources are disposed in the reverse order they were entered.
Declaration
use<T extends Disposable | null | undefined>(value: T): T;
Type Parameters
- T
Parameters
- value
- T
The resource to add.
Returns
The resource provided.