| <html> | |
| <head> | |
| <title>Run parallel</title> | |
| </head> | |
| <body> | |
| <script> | |
| (async function() { | |
| async function f1() { | |
| return new Promise(res => { | |
| setTimeout(() => { | |
| res("1.1"); | |
| }, 1000); | |
| }); | |
| } | |
| async function f2() { | |
| return new Promise(res => { | |
| setTimeout(() => { | |
| res("2.1"); | |
| }, 100); | |
| }); | |
| } | |
| function runParallel(pArr) { | |
| // implement here | |
| } | |
| for await (const results of runParallel([f1(), f2()])) { | |
| console.log(results); | |
| } | |
| /** | |
| * should output 2 lines: | |
| * | |
| * [undefined, "2.1"] // (after 100 ms) | |
| * ["1.1", "2.1"] // (after 1000 ms) | |
| */ | |
| })(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Had a great time playing with this quiz, thanks!