Skip to content

Instantly share code, notes, and snippets.

@vdegenne
Created April 1, 2018 10:38
Show Gist options
  • Save vdegenne/39bfa80d70b767244eaf8570b0d25a48 to your computer and use it in GitHub Desktop.
Save vdegenne/39bfa80d70b767244eaf8570b0d25a48 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const highFive = () => new Promise((res, rej) => {
res('clap!');
});
(async function() {
// 1. correct but prefer syntax 2
await highFive()
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
// 2.
try {
console.log(await highFive());
} catch (e) {
console.error(err);
}
// 3.
highFive().then(res => {console.log(res)});
console.log('get executed before "clap!" just above.');
// 4.
console.log(await highFive());
console.log('get executed after the "clap!" just above.')
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment