Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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();
Add Comment
Please, Sign In to add comment