Parallel Promises

Parallel Promises

Medium NodeJS Async & Event Loop 33 views
Explanation Complexity

Problem Statement

Run two promises in parallel with Promise.all and print combined result.

Input Format

No input.

Output Format

Print one line.

Constraints

Use setTimeout wrapped in Promise.

Input / Output Format

Input Format
No input.
Output Format
Print one line.
Constraints
Use setTimeout wrapped in Promise.

Examples

Input:
Output:
meetcode-42

Example Solution (Public)

NodeJS
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));

Official Solution Code

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));
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.