From bccbbdaa83c41ffd796d7759944e3260e334423a Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Wed, 3 Jul 2013 00:33:25 -0700 Subject: [PATCH] Added progress handlers to Q.when --- q/Q-tests.ts | 5 ++++- q/Q.d.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/q/Q-tests.ts b/q/Q-tests.ts index af8aa7ef23..943f2bb4e2 100644 --- a/q/Q-tests.ts +++ b/q/Q-tests.ts @@ -86,4 +86,7 @@ Q.all(promiseArray).then(nums => nums.map(num => num.toPrecision(2)).join(',')); Q.all(myNums).then(nums => nums.map(Math.round)); -Q.fbind((dateString) => new Date(dateString), "11/11/1991")().then(d => d.toLocaleDateString()); \ No newline at end of file +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(',')); \ No newline at end of file diff --git a/q/Q.d.ts b/q/Q.d.ts index 3665260308..4dc20fb375 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -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(value: T): Promise; export function when(value: IPromise): Promise; + + // If a non-promise value is provided, it will not reject or progress export function when(value: T, onFulfilled: (val: T) => U): Promise; export function when(value: T, onFulfilled: (val: T) => IPromise): Promise; - export function when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason) => U): Promise; - export function when(value: IPromise, onFulfilled: (val: T) => IPromise, onRejected?: (reason) => U): Promise; - export function when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason) => IPromise): Promise; - export function when(value: IPromise, onFulfilled: (val: T) => IPromise, onRejected?: (reason) => IPromise): Promise; + + export function when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason) => U, onProgress?: (progress) => any): Promise; + export function when(value: IPromise, onFulfilled: (val: T) => IPromise, onRejected?: (reason) => U, onProgress?: (progress) => any): Promise; + export function when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason) => IPromise, onProgress?: (progress) => any): Promise; + export function when(value: IPromise, onFulfilled: (val: T) => IPromise, onRejected?: (reason) => IPromise, onProgress?: (progress) => any): Promise; //export function try(method: Function, ...args: any[]): Promise; // <- This is broken currently - not sure how to fix.