0
0
Node.jsframework~5 mins

Promise.all for parallel execution in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does Promise.all do in JavaScript?

Promise.all runs multiple promises at the same time and waits for all of them to finish. It returns a new promise that resolves with an array of results when all promises succeed, or rejects if any promise fails.

Click to reveal answer
beginner
How does Promise.all handle errors from promises?

If any promise inside Promise.all rejects (fails), the whole Promise.all promise immediately rejects with that error. It stops waiting for other promises.

Click to reveal answer
beginner
Why use Promise.all instead of awaiting promises one by one?

Using Promise.all runs promises in parallel, so tasks happen at the same time. Awaiting one by one runs them in order, which is slower.

Click to reveal answer
beginner
What is the output of Promise.all([Promise.resolve(1), Promise.resolve(2)])?

The output is a promise that resolves to [1, 2], an array of the resolved values from each promise.

Click to reveal answer
intermediate
Can Promise.all be used with non-promise values?

Yes. Non-promise values are treated as resolved promises immediately. So Promise.all([1, Promise.resolve(2)]) resolves to [1, 2].

Click to reveal answer
What happens if one promise in Promise.all rejects?
AThe entire <code>Promise.all</code> rejects immediately.
BIt waits for all promises to finish before rejecting.
CIt ignores the rejected promise and resolves with others.
DIt retries the rejected promise automatically.
Which is faster when running multiple independent promises?
AUsing <code>Promise.all</code> to run them in parallel.
BRunning promises inside a loop with await.
CAwaiting each promise one by one.
DRunning promises synchronously without promises.
What does Promise.all([]) resolve to?
AA promise that never resolves.
BAn empty array <code>[]</code> immediately.
CAn error because the array is empty.
DUndefined.
Can Promise.all accept a mix of promises and values?
AOnly if values are strings.
BNo, all items must be promises.
COnly if values are numbers.
DYes, values are treated as resolved promises.
What type of value does Promise.all return?
AAn array of promises.
BA boolean.
CA new promise.
DA string.
Explain how Promise.all helps run tasks in parallel and what happens if one task fails.
Think about waiting for all friends to finish a task together.
You got /3 concepts.
    Describe the difference between awaiting promises one by one versus using Promise.all.
    Compare waiting in line versus doing things together.
    You got /3 concepts.