diff --git a/q/Q-tests.ts b/q/Q-tests.ts index 7872f23b2..2e9b7547b 100644 --- a/q/Q-tests.ts +++ b/q/Q-tests.ts @@ -64,6 +64,15 @@ Q.allResolved([]) }) }); +Q(42) + .tap(() => "hello") + .tap(x => { + console.log(x); + }) + .then(x => { + console.log("42 == " + x); + }); + declare var arrayPromise: Q.IPromise; declare var stringPromise: Q.IPromise; declare function returnsNumPromise(text: string): Q.Promise; diff --git a/q/Q.d.ts b/q/Q.d.ts index 590fd92ad..2a239dc18 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -122,6 +122,12 @@ declare module Q { * A sugar method, equivalent to promise.then(function () { throw reason; }). */ thenReject(reason: any): Promise; + + /** + * Attaches a handler that will observe the value of the promise when it becomes fulfilled, returning a promise for that same value, perhaps deferred but not replaced by the promise returned by the onFulfilled handler. + */ + tap(onFulfilled: (value: T) => any): Promise; + timeout(ms: number, message?: string): Promise; /** * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.