/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import type { Logger } from "#log/Logger.js"; import { MaybePromise } from "./Promises.js"; /** * An operation that may be canceled. */ export interface Cancelable { /** * Cancel the operation. */ cancel(reason: any): void; } /** * A {@link PromiseLike} that may be canceled. * * Behaves like a normal promise but does not actually extend {@link Promise} because that's a huge PITA. */ export declare class CancelablePromise implements Promise, Cancelable { #private; /** * Create a new cancelable promise. * * If the promise is rejected due to cancelation, the {@link executor} callbacks have no effect. * * If you supply {@link onCancel} it overwrites the {@link CancelablePromise#onCancel} method. * * @param executor the normal executor supplied to a {@link Promise} constructor * @param onCancel rejection handler supplied with a reason and a callback for optionally rejecting the promise */ constructor(executor: (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void, onCancel?: (reason: Error) => void); /** * Cancel the operation. */ cancel(reason?: unknown): void; /** * Implement cancellation. This is only invoked if the promise has not resolved. * * Throwing causes the promise to reject with the error thrown. The default implementation rethrows {@link reason}. * * This is overwritten if there is an "onCancel" argument to the constructor. */ protected onCancel(reason: Error): void; then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | null): CancelablePromise; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | null): CancelablePromise; finally(onfinally?: (() => void) | null): CancelablePromise; get [Symbol.toStringTag](): string; static is(value: MaybePromise): value is CancelablePromise; static resolve(value: T): CancelablePromise; static reject(cause: any): CancelablePromise; static set logger(logger: Logger | Console); static get logger(): Logger | Console; } //# sourceMappingURL=Cancelable.d.ts.map