Last active
February 12, 2018 09:35
-
-
Save morrxy/5be4755eb1a3dd37e87a70a3fa0ad29b to your computer and use it in GitHub Desktop.
await #await #javascript
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
// 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