Home >Web Front-end >JS Tutorial >## Promise.all: Is it Parallel or Sequential Execution in Node.js?
Question: Does Promise.all(iterable) process promises sequentially or in parallel?
Answer: Promise.all does not execute promises; instead, it merely awaits multiple promises concurrently. The computation and outcome of promises are managed by the code invoking Promise.all.
Question: Is there a way to execute an iterable sequentially in Node.js?
Answer: If you have an iterable of promises, you cannot enforce specific execution order using Promise.all. However, for an iterable of asynchronous functions, you can apply the following reduction:
iterable.reduce((p, fn) => p.then(fn), Promise.resolve())
This method ensures that functions are executed sequentially, with the previous function's result passing to the next function as input.
The above is the detailed content of ## Promise.all: Is it Parallel or Sequential Execution in Node.js?. For more information, please follow other related articles on the PHP Chinese website!