import { GenericCallback } from "../models.mjs"; import { Result } from "../result/models.mjs"; //#region src/promise/models.d.ts /** * A _Promise_ that can be canceled */ declare class CancelablePromise extends Promise { #private; constructor(executor: (resolve: (value: Value) => void, reject: (reason: unknown) => void) => void); /** * Cancel the _Promise_, rejecting it with an optional reason * * @param reason Optional reason for canceling the _Promise_ */ cancel(reason?: unknown): void; } /** * A _Promise_ that was fulfilled */ type FulfilledPromise = { /** * Status of the _Promise_ */ status: typeof PROMISE_TYPE_FULFILLED; /** * Value of the _Promise_ */ value: Awaited; }; type PromiseData = { last: number; result: unknown[]; }; type PromiseHandlers = { resolve: (value: unknown[]) => void; reject: (reason: unknown) => void; }; /** * Options for a _Promise_-handling function */ type PromiseOptions = { /** * AbortSignal for aborting the _Promise_; when aborted, the _Promise_ will reject with the reason of the signal */ signal?: AbortSignal; /** * How long to wait for _(in milliseconds; defaults to `0`)_ */ time?: number; }; type PromiseParameters = { abort: () => void; complete: boolean; data: PromiseData; handlers: PromiseHandlers; index: number; signal?: AbortSignal; value?: unknown; }; /** * _Promise_ handling strategy * * - `complete`: wait for all _Promises_ to settle, then return the results, as an array of fulfilled and/or rejected results * - `first`: rejects on the first rejected _Promise_, and returns an array of values */ type PromiseStrategy = 'complete' | 'first'; /** * An error thrown when a promise times out */ declare class PromiseTimeoutError extends Error { constructor(); } type PromisesItems = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType extends Promise ? Promise : never : Items[ItemsKey] extends Promise ? Promise : Promise }; /** * Options for handling multiple _Promises_ */ type PromisesOptions = { /** * AbortSignal for aborting the _Promises_; when aborted, the _Promises_ will reject with the reason of the signal */ signal?: AbortSignal; /** * Strategy for handling the _Promises_; defaults to `complete` */ strategy?: PromiseStrategy; }; type PromisesResult = { [ItemsKey in keyof Items]: Items[ItemsKey] extends Promise ? Result> : never }; type PromisesUnwrapped = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType extends Promise ? Awaited : never : Items[ItemsKey] extends Promise ? Awaited : never }; type PromisesValue = FulfilledPromise | RejectedPromise; type PromisesValues = { [ItemsKey in keyof Items]: Items[ItemsKey] extends GenericCallback ? ReturnType extends Promise ? PromisesValue> : never : Items[ItemsKey] extends Promise ? PromisesValue> : never }; /** * A _Promise_ that was rejected */ type RejectedPromise = { /** * Status of the _Promise_ */ status: typeof PROMISE_TYPE_REJECTED; /** * Reason for the rejection */ reason: unknown; }; declare const PROMISE_ABORT_EVENT = "abort"; declare const PROMISE_ABORT_OPTIONS: { once: boolean; }; declare const PROMISE_ERROR_NAME = "PromiseTimeoutError"; declare const PROMISE_MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise"; declare const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise"; declare const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise"; declare const PROMISE_MESSAGE_TIMEOUT = "Promise timed out"; declare const PROMISE_STRATEGY_ALL: Set; declare const PROMISE_STRATEGY_DEFAULT: PromiseStrategy; declare const PROMISE_TYPE_FULFILLED = "fulfilled"; declare const PROMISE_TYPE_REJECTED = "rejected"; //#endregion export { CancelablePromise, FulfilledPromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, RejectedPromise };