Skip to content

Instantly share code, notes, and snippets.

@vitalymak
Last active April 30, 2016 11:28
Show Gist options
  • Save vitalymak/8adf9ded5e3b6287ed1b81e8b49cc187 to your computer and use it in GitHub Desktop.
Save vitalymak/8adf9ded5e3b6287ed1b81e8b49cc187 to your computer and use it in GitHub Desktop.
Bluebird finally & tap difference
'use strict';
const Promise = require('bluebird'); // at least 3.3.5
const log = console.log.bind(console); // bind is safeguard for browser
Promise.resolve('value 1')
.tap(log) // value 1
.then(log)// value 1
.then(log)// undefined
.then(() => Promise.reject(new Error('reason 1')))
.tap(() => log('Never printed!'))
.finally(() => log('"finally" is called for rejection but not "tap"')) // "finally" is called for rejection but not "tap"
.catch(log) // [Error: reason 1]
.then(() => Promise.reject(new Error("reason 2")))
.finally(() => Promise.reject(new Error("reason 3")))
.catch(log) // [Error: reason 3]
/*
value 1
value 1
undefined
"finally" is called for rejection but not "tap"
[Error: reason 1]
[Error: reason 3]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment