Guest User

Untitled

a guest
Mar 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const myfunc = (add1, add2) => {
  2. return new Promise((resolve, reject) => {
  3. const new_value = add1 + add2;
  4. setTimeout(() => {
  5. resolve(new_value);
  6. }, 3000);
  7. })
  8. };
  9.  
  10. myfunc(1, 5)
  11. .then((added_value) => {
  12. console.log(`the value is ${added_value}`);
  13. })
  14. .catch((err) => {
  15. console.error(`there was an error ${err}`);
  16. });
  17. //-------------------------------
  18. const myfunc = (add1, add2) => {
  19. return new Promise((resolve, reject) => {
  20. const new_value = add1 + add2;
  21. setTimeout(() => {
  22. console.log(`new value ${new_value}`);
  23. resolve(new_value);
  24. }, 3000);
  25. })
  26. };
  27.  
  28. const mypromises = [
  29. myfunc(1, 5),
  30. myfunc(6, 5),
  31. myfunc(2, 9),
  32. myfunc(10, 5),
  33. ];
  34.  
  35. Promise.all(mypromises)
  36. .then(() => {
  37. console.log('they all resolved');
  38. });
Add Comment
Please, Sign In to add comment