Promise.all result order vs completion
Assume a single browser task. Predict the logs and the order of all results.
Code Snippet
const slow = new Promise(resolve => setTimeout(() => {
console.log("slow finished");
resolve("S");
}, 0));
const fast = Promise.resolve().then(() => {
console.log("fast finished");
return "F";
});
Promise.all([slow, fast, 4]).then(items => console.log(items.join(" ")));Expected Output & Explanation
fast finished
slow finished
S F 4 The fast reaction is a microtask and runs before the timer. all accepts non-promises and places every fulfillment value in input order, not completion order.
Module Context & References
JavaScript · Async output drills Trace microtasks, promise identity, thenables and error recovery
Personal Notes · Markdown