import { Disposables } from './create-disposables.js'; declare const DISPOSAL_GUARD_DEFAULTS: { name: string; timeout: number; usedWhileDisposing: boolean; }; /** * @deprecated * A base class for disposable objects * @example * ```ts * class MyDisposable extends Disposable { * constructor() { * super(); * this.disposables.add(() => console.log('disposed')); * this.setTimeout(() => console.log('will be canceled upon disposal'), 1000); * } * async doSomething() { * // will throw if disposed, delays disposal until done is called * const done = this.disposalGuard(false, true); * try { * // do something * } finally { * // disposal can begin (if dispose was called) * done(); * } * } * } */ export declare class Disposable { private _isDisposed; private _isDisposing; readonly disposables: Disposables; private timeouts; private intervals; constructor(name?: string); /** * Starts instance disposal: * * **phase 1: disposing** * - isDisposed === true * - disposalGuard() will throw * - disposalGuard(true) will not throw (for methods that are used in the disposal process) * - disposable.dispose is awaited * * **phase 2: disposed done** * - disposalGuard(true) will throw */ dispose(): Promise; /** * returns true if the disposal process started */ get isDisposed(): boolean; /** * - throws if disposal started/finished * - in async mode, delays disposal until the returned fn called * @example async mode * ```ts * // this will throw if disposed * const done = this.disposalGuard({timeout: 1000, name:'something'}); * try { * // do something * } finally { * // disposal can begin (if dispose was called) * done(); * } * @example sync mode * ```ts * // will throw if disposed * this.disposalGuard({async:false}); * @example usedWhileDisposing * ```ts * // will not throw if disposal didn't finished yet, even if dispose was called * this.disposalGuard({usedWhileDisposing:true, async:false}); */ disposalGuard(options: { async: never; } & Partial): () => void; disposalGuard(): () => void; disposalGuard(options: { async: false; usedWhileDisposing?: boolean; }): void; /** * a disposal safe setTimeout * checks disposal before execution and clears the timeout when the instance is disposed */ setTimeout(fn: () => void, timeout: number): ReturnType; /** * a disposal safe setInterval * checks disposal before execution and clears the interval when the instance is disposed */ setInterval(fn: () => void, interval: number): ReturnType; } export {}; //# sourceMappingURL=disposable.d.ts.map