Does Promise.all() cancel the other Promises?
Assesses fundamental understanding of JavaScript conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
No. Promise.all() does not cancel the other promises. It only waits for all of them to finish, and if any one rejects, the overall Promise.all() call rejects immediately.
A JavaScript promise does not have a built-in cancel API. Once a promise starts, it keeps running unless the underlying async operation supports cancellation on its own. For example, fetch() supports cancellation using AbortController.
const controller = new AbortController();
const signal = controller.signal;
const requestA = fetch("/api/a", { signal });
const requestB = Promise.reject(new Error("Server error"));
const requestC = fetch("/api/c", { signal });
Promise.all([requestA, requestB, requestC])
.then((results) => console.log(results))
.catch((error) => {
console.log("Promise.all rejected:", error.message);
controller.abort(); // Cancels the fetch requests still in progress
});
In the example above, if requestB rejects, Promise.all() rejects, but requestA and requestC are not automatically canceled. They continue unless you explicitly abort them using the underlying API or custom logic.
How to cancel async work:
- Use an API that supports cancellation, such as
fetch()withAbortController. - For custom promises, you can add a
cancel()method or a flag to stop work internally. - If the work is not cancelable, the promise cannot be truly canceled from outside.
Note: Promise.all() is about aggregation, not cancellation. It waits for all promises to settle, but it does not stop the other async operations by itself.
### What is the difference between return and return await in async functions
In an async function, return value simply returns the value or promise. If the value is a rejected promise, the rejection is not caught by a surrounding try/catch unless you await it first.
return await value pauses the function until the promise settles, so a try/catch around it can handle errors properly.
async function withoutAwait() {
try {
return Promise.reject(new Error("Something failed"));
} catch (error) {
console.log("This will not run");
return "fallback";
}
}
async function withAwait() {
try {
return await Promise.reject(new Error("Something failed"));
} catch (error) {
console.log("Caught inside the function:", error.message);
return "fallback";
}
}
withoutAwait().catch((err) => console.log("outside catch:", err.message));
withAwait().then((value) => console.log("withAwait result:", value));
Output:
outside catch: Something failed
Caught inside the function: Something failed
withAwait result: fallback
In short:
return promisereturns the promise without waiting for it.return await promisewaits for the promise and allows the surroundingtry/catchto catch errors.
return await is especially useful when you want to clean up or handle the error inside the same async function before it exits.
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.