W3cubDocs

/Bluebird

.tap

.tap(function(any value) handler) -> Promise

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–2017 Petka Antonov
Licensed under the MIT License.
http://bluebirdjs.com/docs/api/tap.html