Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
Last active May 27, 2019 18:59
Show Gist options
  • Select an option

  • Save vbarbarosh/d020d5ea79c6d4008bb4f3acfe54e9ff to your computer and use it in GitHub Desktop.

Select an option

Save vbarbarosh/d020d5ea79c6d4008bb4f3acfe54e9ff to your computer and use it in GitHub Desktop.
node_promise_then – How Promise.then is designed to work https://codescreens.com
const Promise = require('bluebird');
// How Promise.then is designed to work
// $ node node_promise_then.js
main().catch(panic);
async function main()
{
// FULFILLED
await Promise.resolve(1).then(fulfilled, rejected);
// REJECTED
await Promise.reject(new Error('555')).then(fulfilled, rejected);
// MISSED
try {
await Promise.resolve(1).then(() => {throw new Error('555')}, rejected);
}
catch (error) {
console.log('MISSED', error);
}
}
function fulfilled(value)
{
console.log('FULFILLED', value);
}
function rejected(error)
{
console.log('REJECTED', error);
}
function panic(error)
{
console.error('error:', error);
process.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment