Guest User

Untitled

a guest
Feb 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. // parallel
  2. await Promise.all([someCall(), anotherCall()]);
  3.  
  4. // error handle use promise
  5. function foo() {
  6. return bar();
  7. }
  8.  
  9. function bar() {
  10. return Promise.reject(new Error('Uh oh!'));
  11. }
  12.  
  13. function main() {
  14. return foo().catch(e => {
  15. console.error(`Something went wrong: ${e.message}`);
  16. });
  17. }
  18.  
  19. main();
  20.  
  21. // error handle use await
  22. async function foo() {
  23. await bar();
  24. }
  25.  
  26. async function bar() {
  27. throw new Error('Uh oh!');
  28. }
  29.  
  30. async function main() {
  31. try {
  32. await foo();
  33. }
  34. catch(e) {
  35. console.error(`Something went wrong: ${e.message}`);
  36. }
  37. }
  38.  
  39. main();
Add Comment
Please, Sign In to add comment