Skip to content

Instantly share code, notes, and snippets.

@secretgspot
Created January 31, 2020 22:41
Show Gist options
  • Save secretgspot/683d2c69a1b73bc4a3410b1545044822 to your computer and use it in GitHub Desktop.
Save secretgspot/683d2c69a1b73bc4a3410b1545044822 to your computer and use it in GitHub Desktop.
let arrived = true;
// Create a Promise
const ride = new Promise((resolve, reject) => {
if (arrived) {
resolve('driver arrived');
} else {
reject({msg: 'rejected', code: 222});
}
});
// Consume a Promise
ride
.then(value => {
console.log('val: ', value);
})
.catch(err => {
console.log('err: ', err);
})
.finally(() => {
console.log('do cleanup')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment