.tap(function(any value) handler) -> Promise
Essentially like .then()
, except that the value passed in is the value returned.
This means you can insert .tap()
into a .then()
chain without affecting what is passed through the chain. (See example below).
Unlike .finally
this is not called for rejections.
getUser().tap(function(user) { //Like in finally, if you return a promise from the handler //the promise is awaited for before passing the original value through return recordStatsAsync(); }).then(function(user) { //user is the user from getUser(), not recordStatsAsync() });
Common case includes adding logging to an existing promise chain:
doSomething() .then(...) .then(...) .then(...) .then(...)
doSomething() .then(...) .then(...) .tap(console.log) .then(...) .then(...)
Note: in browsers it is necessary to call .tap
with console.log.bind(console)
because console methods can not be called as stand-alone functions.
© 2013–2018 Petka Antonov
Licensed under the MIT License.
http://bluebirdjs.com/docs/api/tap.html