Last active
May 27, 2019 18:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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