/** * The methods of this interface are available when a Promise * has been augmented using the `trackState` function. */ interface StateQueryable { /** Returns true if the promise is settled, i.e. if it is no longer pending. */ isSettled(): boolean; /** Returns true if the promise is fulfilled, i.e. if it has a success value. */ isFulfilled(): boolean; /** Returns true if the promise is rejected, i.e. if it contains an error. */ isRejected(): boolean; /** Returns true if the promise was cancelled before it was able to complete. */ isCancelled(): boolean; } type State = "pending" | "fulfilled" | "rejected" | "cancelled"; declare const PROMISE: unique symbol; declare const STATE: unique symbol; declare const PRIVATE_CONSTRUCTOR_TAG: unique symbol; /** * Wrapper of global.Promise class. * Read more about [Promises](./PROMISES.md). * * @see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise */ declare class ExtendedPromise implements Promise { private [PROMISE]; private [STATE]?; /** * Creates Promise instances. * @param executor defined as (resolve,reject)=> \{\} * @example * ```ts * new Promise((resolve, reject)=>{ * ... * }); * ``` */ constructor(executor: (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void); /** * Internal constructor. Do not call. */ constructor(promise: PromiseLike | LegacyDojoDeferred, state: State | undefined, tag: typeof PRIVATE_CONSTRUCTOR_TAG); /** Creates a new resolved promise */ static resolve(): ExtendedPromise; /** * Creates a new resolved promise with the given value * @param value result object. * @returns a promise in fulfilled state. */ static resolve(value: T): ExtendedPromise; /** * @param reason The reason the promise was rejected. * @returns a promise in rejected state. */ static reject(reason?: any): ExtendedPromise; /** * Creates promise which fulfills if all other promises are fulfilled. * Or rejects if one of the promises rejects. * * @param iterable Iterable of Promise instances */ static all(iterable: T): ExtendedPromise<{ -readonly [P in keyof T]: Awaited; }>; /** * Creates promise which fulfills if one of the other promises fulfills. * Or rejects if one of the promises rejects. * * @param iterable Iterable of Promise instances */ static race(iterable: Iterable): ExtendedPromise ? U : T>; /** * Creates promise which fulfills if one of the other promises fulfills. * Or rejects if one of the promises rejects. * * @param iterable Iterable of Promise instances */ static race(iterable: Iterable>): ExtendedPromise; /** * Creates a promise that resolves after all of the given promises have either fulfilled or rejected, * with an array of objects that each describes the outcome of each promise. * * @param iterable Iterable of Promise instances */ static allSettled(iterable: Iterable>): ExtendedPromise>[]>; /** * Promise.any() takes an iterable of Promise objects and, as soon as one of the promises in the iterable fulfills, * returns a single promise that resolves with the value from that promise. * If no promises in the iterable fulfill (if all of the given promises are rejected), * then the returned promise is rejected with an AggregateError, * Essentially, this method is the opposite of Promise.all(). * * @param iterable Iterable of Promise instances */ static any(iterable: (T | PromiseLike)[] | Iterable>): ExtendedPromise; /** * Produces an object with a promise along with its resolution and rejection functions. * Allows to resolve/reject the promise manually after creating it. * * @example * ```ts * const { promise, resolve, reject } = Promise.withResolvers(); * ``` * @returns {{ promise, resolve, reject }} */ static withResolvers(): { resolve: (value: T | PromiseLike) => void; reject: (reason?: unknown) => void; promise: ExtendedPromise; }; /** * This method tests if a given object is a promise. * The algorithm will return true for: * * apprt-core/Promise * * global Promise * * dojo/Deferred * * dojo/Deferred.promise * * Note: Because of support for dojo/Deferred any object with a * 'then', 'isResolved' and 'isRejected' method is detected as a promise. * * @param candidate a potential promise. * @returns true if candidate is a promise. */ static isPromise(candidate: any): candidate is PromiseLike; /** * Wraps e.g. dojo/Deferred or native Promise to this Promise class. * @returns a promise */ static wrap(promise: PromiseLike | LegacyDojoDeferred): ExtendedPromise; /** * Augments the given Promise with new state lookup functions. */ static trackState(promise: PromiseLike | LegacyDojoDeferred): ExtendedPromise & StateQueryable; /** * Registers success and/or error handlers. * @param success called when the promise resolves * @param failure called when the promise rejects */ then(success?: ((value: T) => TResult1 | PromiseLike) | undefined | null, failure?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): ExtendedPromise; /** * Registers an error handler. * @param failure called when the promise rejects */ catch(failure?: ((reason: any) => TResult | PromiseLike) | undefined | null): ExtendedPromise; /** * Registers an error handler. Which is not called if the error is a Cancel instance. * @param failure called when the promise rejects */ else(failure?: ((reason: any) => TResult | PromiseLike) | undefined | null): ExtendedPromise; /** * Registers a handler, which is called in success or error state. * But the handler is not able to change the result state! * @param handler function invoked regardless of success or error */ finally(handler?: (() => void) | undefined | null): ExtendedPromise; /** * @returns this instance, augmented with augmented with: * * * isFulfilled() * * isRejected() * * isCancelled() * * isSettled() */ trackState(): ExtendedPromise & StateQueryable; get [Symbol.toStringTag](): string; } interface LegacyDojoDeferred { promise: any; isResolved(): boolean; isRejected(): boolean; isFulfilled(): boolean; isCanceled(): boolean; progress(update: any, strict?: boolean): any; resolve(value?: any, strict?: boolean): any; reject(error?: any, strict?: boolean): any; then(callback?: any, errback?: any, progback?: any): any; cancel(reason?: any, strict?: boolean): any; toString(): string; } export { ExtendedPromise, ExtendedPromise as default }; export type { StateQueryable };