From c969d6275cf4832f24aae3ea9a4eec3730f8c8da Mon Sep 17 00:00:00 2001 From: Florent Chiron Date: Fri, 1 May 2015 03:30:41 +0200 Subject: [PATCH] Add signature for promise.tap(onFulfilled) --- q/Q-tests.ts | 9 +++++++++ q/Q.d.ts | 6 ++++++ 2 files changed, 15 insertions(+) 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.