/**
 * @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<T = void> implements Promise<T>, 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<T>) => 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<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): CancelablePromise<TResult1 | TResult2>;
    catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): CancelablePromise<T | TResult>;
    finally(onfinally?: (() => void) | null): CancelablePromise<T>;
    get [Symbol.toStringTag](): string;
    static is<T>(value: MaybePromise<T>): value is CancelablePromise<T>;
    static resolve<T>(value: T): CancelablePromise<T>;
    static reject(cause: any): CancelablePromise<any>;
    static set logger(logger: Logger | Console);
    static get logger(): Logger | Console;
}
//# sourceMappingURL=Cancelable.d.ts.map