Queue Tasks One By One
NodeJS
Medium
4 views
Problem Description
Process async tasks in order (not parallel) and print final array.
Output Format
Print JSON array.
Constraints
Use for..of with await.
Official Solution
function wait(ms, value) {
return new Promise((resolve) => setTimeout(() => resolve(value), ms));
}
(async () => {
const out = [];
for (const v of [1, 2, 3]) {
out.push(await wait(10, v));
}
console.log(JSON.stringify(out));
})();
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!