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