Guest User

Untitled

a guest
Jan 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Run parallel</title>
  4. </head>
  5. <body>
  6. <script>
  7. (async function() {
  8. async function f1() {
  9. return new Promise(res => {
  10. setTimeout(() => {
  11. res("1.1");
  12. }, 1000);
  13. });
  14. }
  15.  
  16. async function f2() {
  17. return new Promise(res => {
  18. setTimeout(() => {
  19. res("2.1");
  20. }, 100);
  21. });
  22. }
  23.  
  24. function runParallel(pArr) {
  25. // implement here
  26. }
  27.  
  28. for await (const results of runParallel([f1(), f2()])) {
  29. console.log(results);
  30. }
  31.  
  32. /**
  33. * should output 2 lines:
  34. *
  35. * [undefined, "2.1"] // (after 100 ms)
  36. * ["1.1", "2.1"] // (after 1000 ms)
  37. */
  38. })();
  39. </script>
  40. </body>
  41. </html>
Add Comment
Please, Sign In to add comment