Skip to content

Instantly share code, notes, and snippets.

@agentcooper
Created January 21, 2019 14:30
Show Gist options
  • Save agentcooper/5b71ed04c802f1fe9b276b919fea0177 to your computer and use it in GitHub Desktop.
Save agentcooper/5b71ed04c802f1fe9b276b919fea0177 to your computer and use it in GitHub Desktop.
<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>
@peter-leonov
Copy link

Had a great time playing with this quiz, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment