Skip to content

Instantly share code, notes, and snippets.

@morrxy
Last active February 12, 2018 09:35
Show Gist options
  • Save morrxy/5be4755eb1a3dd37e87a70a3fa0ad29b to your computer and use it in GitHub Desktop.
Save morrxy/5be4755eb1a3dd37e87a70a3fa0ad29b to your computer and use it in GitHub Desktop.
await #await #javascript
// parallel
await Promise.all([someCall(), anotherCall()]);
// error handle use promise
function foo() {
return bar();
}
function bar() {
return Promise.reject(new Error('Uh oh!'));
}
function main() {
return foo().catch(e => {
console.error(`Something went wrong: ${e.message}`);
});
}
main();
// error handle use await
async function foo() {
await bar();
}
async function bar() {
throw new Error('Uh oh!');
}
async function main() {
try {
await foo();
}
catch(e) {
console.error(`Something went wrong: ${e.message}`);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment