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
    string

    disposed

    Gets a value indicating whether the stack has already been disposed.

    Declaration
    get disposed(): boolean;
    Property Value
    boolean

    Methods

    [Disposable.dispose]()

    Dispose this object's resources.

    Declaration
    [Disposable.dispose](): void;
    Returns
    void

    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
    T

    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
    void

    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
    void

    move()

    Moves all resources out of this DisposableStack and into a new DisposableStack and returns it.

    Declaration
    move(): DisposableStack;
    Returns
    DisposableStack

    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
    T

    The resource provided.

    Generated by DocFX