Created
January 21, 2019 14:30
-
-
Save agentcooper/5b71ed04c802f1fe9b276b919fea0177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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
Had a great time playing with this quiz, thanks!