Created
April 1, 2018 10:38
-
-
Save vdegenne/39bfa80d70b767244eaf8570b0d25a48 to your computer and use it in GitHub Desktop.
This file contains 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
#!/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