Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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

This comment has been minimized.

Copy link

@peter-leonov peter-leonov commented Apr 13, 2020

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