/** * Utils for promises. * * @license * Copyright 2022-2024 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { MatterError } from "../MatterError.js"; /** * Obtain a promise with functions to resolve and reject. */ export declare function createPromise(): { promise: Promise; resolver: (value: T) => void; rejecter: (reason?: any) => void; }; /** * Use all promises or promise returning methods and return the first resolved promise or reject when all promises * rejected */ export declare function anyPromise(promises: ((() => Promise) | Promise)[]): Promise; /** * Thrown when a timed promise times out. */ export declare class PromiseTimeoutError extends MatterError { constructor(message?: string); } /** * Create a promise with a timeout. * * By default rejects with {@link PromiseTimeoutError} on timeout but you can override by supplying {@link cancel}. * * @param timeoutMs the timeout in milliseconds * @param promise a promise that resolves or rejects when the timed task completes * @param cancel invoked on timeout (default implementation throws {@link PromiseTimeoutError}) */ export declare function withTimeout(timeoutMs: number, promise: Promise, cancel?: AbortController | (() => void)): Promise; /** * Return type for functions that are optionally asynchronous. * * TODO - as currently defined MaybePromise of a Promise incorrectly wraps as a Promise of a Promise */ export type MaybePromise = T | PromiseLike; /** * Promise-like version of above. */ export type MaybePromiseLike = T | PromiseLike; export declare const MaybePromise: { /** * Determine whether a {@link MaybePromiseLike} is a {@link Promise}. */ is(value: MaybePromise): value is PromiseLike; /** * Chained MaybePromise. Invokes the resolve function immediately if the {@link MaybePromise} is not a * {@link Promise}, otherwise the same as a normal {@link Promise.then}. */ then(producer: MaybePromise | (() => MaybePromise), resolve?: ((input: I) => MaybePromise) | null, reject?: ((error: any) => MaybePromise) | null): MaybePromise; /** * Equivalent of {@link Promise.catch}. */ catch(producer: MaybePromise | (() => MaybePromise), onrejected?: ((reason: any) => MaybePromise) | undefined | null): MaybePromise; /** * Equivalent of {@link Promise.finally}. */ finally(producer: MaybePromise | (() => MaybePromise), onfinally?: (() => MaybePromise) | undefined | null): MaybePromise; [Symbol.toStringTag]: string; }; //# sourceMappingURL=Promises.d.ts.map