import { Iterable } from 'dojo-shim/iterator'; import Promise, { Executor } from 'dojo-shim/Promise'; import { Thenable } from 'dojo-shim/interfaces'; export declare type DictionaryOfPromises = { [_: string]: T | Promise | Thenable; }; export declare type ListOfPromises = Iterable<(T | Thenable)>; /** * An extensible base to allow Promises to be extended in ES5. This class basically wraps a native Promise object, * giving an API like a native promise. */ export default class ExtensiblePromise { /** * Return a rejected promise wrapped in an ExtensiblePromise * * @param {Error?} reason The reason for the rejection * @returns {ExtensiblePromise} */ static reject(reason?: Error): any; /** * Return a resolved promise wrapped in an ExtensiblePromise * * @param value The value to resolve the promise with * * @returns {ExtensiblePromise} */ static resolve>(): F; static resolve>(value: (T | Thenable)): F; /** * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values. * * @example * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results)); * // { one: 1, two: 2 } * * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects * @returns {ExtensiblePromise} */ static all, T>(iterable: DictionaryOfPromises): F; static all, T>(iterable: (T | Thenable)[]): F; static all, T>(iterable: T | Thenable): F; static all, T>(iterable: ListOfPromises): F; /** * Return a ExtensiblePromise that resolves when one of the passed in objects have resolved * * @param iterable An iterable of values to resolve. These can be Promises, ExtensiblePromises, or other objects * @returns {ExtensiblePromise} */ static race, T>(iterable: Iterable<(T | Thenable)> | (T | Thenable)[]): F; /** * @type {Promise} * The wrapped promise */ readonly _promise: Promise; /** * Creates a new extended Promise. * * @constructor * * @param executor * The executor function is called immediately when the Promise is instantiated. It is responsible for * starting the asynchronous operation when it is invoked. * * The executor must call either the passed `resolve` function when the asynchronous operation has completed * successfully, or the `reject` function when the operation fails. */ constructor(executor: Executor); /** * Adds a callback to be invoked when the wrapped Promise is rejected. * * @param {Function} onRejected A function to call to handle the error. The parameter to the function will be the caught error. * * @returns {ExtensiblePromise} */ catch(onRejected: (reason: Error) => T | Thenable | void): ExtensiblePromise; /** * Adds a callback to be invoked when the wrapped Promise resolves or is rejected. * * @param {Function} onFulfilled A function to call to handle the resolution. The paramter to the function will be the resolved value, if any. * @param {Function} onRejected A function to call to handle the error. The parameter to the function will be the caught error. * * @returns {ExtensiblePromise} */ then(onFulfilled: ((value: T) => (U | Thenable | undefined)) | undefined, onRejected: (reason: Error) => (V | Thenable)): ExtensiblePromise; then(onFulfilled?: ((value: T) => (U | Thenable | undefined)) | undefined, onRejected?: (reason: Error) => void): ExtensiblePromise; }