interface PromiseFactory { (...args: any[]): Promise; } export declare const pendingPromise: Promise; export declare function delay(ms: number): Promise; /** * Detect if `maybePromise` is a Promise. * @param {any} maybePromise * @returns {boolean} */ export declare function isPromise(maybePromise: any): maybePromise is Promise; /** * Given a function that returns a Promise, this will return a new * function that returns a Promise such that only the latest created * Promise will resolve or reject. * * A pattern where this is useful is if you are listening to events that are * fired repeatedly, but you only care about the latest event, such as a * keypress in an input box. Each keypress can invoke a function that * makes an ajax request and returns a Promise that resolves with the response. * By applying `latestPromise` to this function, there is no need to cancel the * previous requests, or to track which is the latest. * * @param {Function} promiseFactory A function that returns a Promise. * @returns {Function} A function that returns a Promise. */ export declare function latest(promiseFactory: PromiseFactory): (this: any, ...args: any[]) => Promise; /** * Function decorator that returns a new function such that each call waits for * the previous call's returned Promise to resolve before proceeding. * * @param promiseFactory Function that produces Promises */ export declare function synchronized(promiseFactory: PromiseFactory): PromiseFactory; /** * Calls `resolveHandler` and `rejectHandler` in the order of the promises * in `promiseArray`, even if they resolve out of order. * * @param {Array>} promiseArray * @param {Function} resolveHandler * @param {Function} rejectHandler * @returns {Promise} */ export declare function seq(promiseArray: Promise[], resolveHandler: (res: any) => any, rejectHandler: (err: Error) => any): Promise; export declare class Mutex { private _queue; synchronize(callback: () => Promise): Promise; } interface Deferred extends Promise { resolve(value: any): void; reject(value: any): void; asPromise(): Promise; } /** * A Deffered is a way to expose the internals of a Promise's state management * functionality (e.g., resolve and reject functions). This makes it possible * to resolve or reject a Promise externally. * * You convert a deferred to a plain Promise using the `asPromise` method. This * is useful to hide the internals to a consumer: * ``` * var deferred = createDeferred(); * // ... * return deferred.asPromise(); * ``` */ export declare function createDeferred(): Deferred; export {}; //# sourceMappingURL=PromiseUtils.d.ts.map