Parallel Promises
NodeJS
Medium
3 views
Problem Description
Run two promises in parallel with Promise.all and print combined result.
Output Format
Print one line.
Constraints
Use setTimeout wrapped in Promise.
Official Solution
function wait(ms, value) {
return new Promise((resolve) => setTimeout(() => resolve(value), ms));
}
Promise.all([wait(30, 'meetcode'), wait(10, 42)])
.then(([a, b]) => console.log(a + '-' + b));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!