Added progress handlers to Q.when

This commit is contained in:
Andrew Gaspar
2013-07-03 00:33:25 -07:00
parent 6fb97f40bf
commit bccbbdaa83
2 changed files with 12 additions and 5 deletions

View File

@@ -86,4 +86,7 @@ Q.all(promiseArray).then(nums => nums.map(num => num.toPrecision(2)).join(','));
Q.all<number>(myNums).then(nums => nums.map(Math.round));
Q.fbind((dateString) => new Date(dateString), "11/11/1991")().then(d => d.toLocaleDateString());
Q.fbind((dateString) => new Date(dateString), "11/11/1991")().then(d => d.toLocaleDateString());
Q.when(8, num => num + "!");
Q.when(Q(8), num => num + "!").then(str => str.split(','));

12
q/Q.d.ts vendored
View File

@@ -62,14 +62,18 @@ declare module Q {
valueOf(): any;
}
// if no fulfill, reject, or progress provided, returned promise will be of same type
export function when<T>(value: T): Promise<T>;
export function when<T>(value: IPromise<T>): Promise<T>;
// If a non-promise value is provided, it will not reject or progress
export function when<T, U>(value: T, onFulfilled: (val: T) => U): Promise<U>;
export function when<T, U>(value: T, onFulfilled: (val: T) => IPromise<U>): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => U, onRejected?: (reason) => U): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => IPromise<U>, onRejected?: (reason) => U): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => U, onRejected?: (reason) => IPromise<U>): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => IPromise<U>, onRejected?: (reason) => IPromise<U>): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => U, onRejected?: (reason) => U, onProgress?: (progress) => any): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => IPromise<U>, onRejected?: (reason) => U, onProgress?: (progress) => any): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => U, onRejected?: (reason) => IPromise<U>, onProgress?: (progress) => any): Promise<U>;
export function when<T, U>(value: IPromise<T>, onFulfilled: (val: T) => IPromise<U>, onRejected?: (reason) => IPromise<U>, onProgress?: (progress) => any): Promise<U>;
//export function try(method: Function, ...args: any[]): Promise<any>; // <- This is broken currently - not sure how to fix.