CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
lib.esnext.disposable.d.ts192 linesDownload Raw Back to lib
1/*! *****************************************************************************2Copyright (c) Microsoft Corporation. All rights reserved.3Licensed under the Apache License, Version 2.0 (the "License"); you may not use4this file except in compliance with the License. You may obtain a copy of the5License at http://www.apache.org/licenses/LICENSE-2.06 7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,10MERCHANTABILITY OR NON-INFRINGEMENT.11 12See the Apache Version 2.0 License for specific language governing permissions13and limitations under the License.14***************************************************************************** */15 16 17/// <reference lib="es2015.symbol" />18/// <reference lib="es2015.iterable" />19/// <reference lib="es2018.asynciterable" />20 21interface SymbolConstructor {22    /**23     * A method that is used to release resources held by an object. Called by the semantics of the `using` statement.24     */25    readonly dispose: unique symbol;26 27    /**28     * A method that is used to asynchronously release resources held by an object. Called by the semantics of the `await using` statement.29     */30    readonly asyncDispose: unique symbol;31}32 33interface Disposable {34    [Symbol.dispose](): void;35}36 37interface AsyncDisposable {38    [Symbol.asyncDispose](): PromiseLike<void>;39}40 41interface SuppressedError extends Error {42    error: any;43    suppressed: any;44}45 46interface SuppressedErrorConstructor {47    new (error: any, suppressed: any, message?: string): SuppressedError;48    (error: any, suppressed: any, message?: string): SuppressedError;49    readonly prototype: SuppressedError;50}51declare var SuppressedError: SuppressedErrorConstructor;52 53interface DisposableStack {54    /**55     * Returns a value indicating whether this stack has been disposed.56     */57    readonly disposed: boolean;58    /**59     * Disposes each resource in the stack in the reverse order that they were added.60     */61    dispose(): void;62    /**63     * Adds a disposable resource to the stack, returning the resource.64     * @param value The resource to add. `null` and `undefined` will not be added, but will be returned.65     * @returns The provided {@link value}.66     */67    use<T extends Disposable | null | undefined>(value: T): T;68    /**69     * Adds a value and associated disposal callback as a resource to the stack.70     * @param value The value to add.71     * @param onDispose The callback to use in place of a `[Symbol.dispose]()` method. Will be invoked with `value`72     * as the first parameter.73     * @returns The provided {@link value}.74     */75    adopt<T>(value: T, onDispose: (value: T) => void): T;76    /**77     * Adds a callback to be invoked when the stack is disposed.78     */79    defer(onDispose: () => void): void;80    /**81     * Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.82     * @example83     * ```ts84     * class C {85     *   #res1: Disposable;86     *   #res2: Disposable;87     *   #disposables: DisposableStack;88     *   constructor() {89     *     // stack will be disposed when exiting constructor for any reason90     *     using stack = new DisposableStack();91     *92     *     // get first resource93     *     this.#res1 = stack.use(getResource1());94     *95     *     // get second resource. If this fails, both `stack` and `#res1` will be disposed.96     *     this.#res2 = stack.use(getResource2());97     *98     *     // all operations succeeded, move resources out of `stack` so that they aren't disposed99     *     // when constructor exits100     *     this.#disposables = stack.move();101     *   }102     *103     *   [Symbol.dispose]() {104     *     this.#disposables.dispose();105     *   }106     * }107     * ```108     */109    move(): DisposableStack;110    [Symbol.dispose](): void;111    readonly [Symbol.toStringTag]: string;112}113 114interface DisposableStackConstructor {115    new (): DisposableStack;116    readonly prototype: DisposableStack;117}118declare var DisposableStack: DisposableStackConstructor;119 120interface AsyncDisposableStack {121    /**122     * Returns a value indicating whether this stack has been disposed.123     */124    readonly disposed: boolean;125    /**126     * Disposes each resource in the stack in the reverse order that they were added.127     */128    disposeAsync(): Promise<void>;129    /**130     * Adds a disposable resource to the stack, returning the resource.131     * @param value The resource to add. `null` and `undefined` will not be added, but will be returned.132     * @returns The provided {@link value}.133     */134    use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;135    /**136     * Adds a value and associated disposal callback as a resource to the stack.137     * @param value The value to add.138     * @param onDisposeAsync The callback to use in place of a `[Symbol.asyncDispose]()` method. Will be invoked with `value`139     * as the first parameter.140     * @returns The provided {@link value}.141     */142    adopt<T>(value: T, onDisposeAsync: (value: T) => PromiseLike<void> | void): T;143    /**144     * Adds a callback to be invoked when the stack is disposed.145     */146    defer(onDisposeAsync: () => PromiseLike<void> | void): void;147    /**148     * Move all resources out of this stack and into a new `DisposableStack`, and marks this stack as disposed.149     * @example150     * ```ts151     * class C {152     *   #res1: Disposable;153     *   #res2: Disposable;154     *   #disposables: DisposableStack;155     *   constructor() {156     *     // stack will be disposed when exiting constructor for any reason157     *     using stack = new DisposableStack();158     *159     *     // get first resource160     *     this.#res1 = stack.use(getResource1());161     *162     *     // get second resource. If this fails, both `stack` and `#res1` will be disposed.163     *     this.#res2 = stack.use(getResource2());164     *165     *     // all operations succeeded, move resources out of `stack` so that they aren't disposed166     *     // when constructor exits167     *     this.#disposables = stack.move();168     *   }169     *170     *   [Symbol.dispose]() {171     *     this.#disposables.dispose();172     *   }173     * }174     * ```175     */176    move(): AsyncDisposableStack;177    [Symbol.asyncDispose](): Promise<void>;178    readonly [Symbol.toStringTag]: string;179}180 181interface AsyncDisposableStackConstructor {182    new (): AsyncDisposableStack;183    readonly prototype: AsyncDisposableStack;184}185declare var AsyncDisposableStack: AsyncDisposableStackConstructor;186 187interface IteratorObject<T, TReturn, TNext> extends Disposable {188}189 190interface AsyncIteratorObject<T, TReturn, TNext> extends AsyncDisposable {191}192