Documentation
    Preparing search index...

    Implements

    • DisposableStack
    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    "[toStringTag]": "jscorlib::DisposableStack"

    Accessors

    Methods

    • Adds a value and associated disposal callback as a resource to the stack.

      Type Parameters

      • T

      Parameters

      • value: T

        The value to add.

      • onDispose: (value: T) => void

        The callback to use in place of a [Symbol.dispose]() method. Will be invoked with value as the first parameter.

      Returns T

      The provided value.

    • Move all resources out of this stack and into a new DisposableStack, and marks this stack as disposed.

      Returns DisposableStack

      class C {
      #res1: Disposable;
      #res2: Disposable;
      #disposables: DisposableStack;
      constructor() {
      // stack will be disposed when exiting constructor for any reason
      using stack = new DisposableStack();

      // get first resource
      this.#res1 = stack.use(getResource1());

      // get second resource. If this fails, both `stack` and `#res1` will be disposed.
      this.#res2 = stack.use(getResource2());

      // all operations succeeded, move resources out of `stack` so that they aren't disposed
      // when constructor exits
      this.#disposables = stack.move();
      }

      [Symbol.dispose]() {
      this.#disposables.dispose();
      }
      }
    • Adds a disposable resource to the stack, returning the resource.

      Type Parameters

      • T extends undefined | null | Disposable

      Parameters

      • value: T

        The resource to add. null and undefined will not be added, but will be returned.

      Returns T

      The provided value.