Question:
When employing async/await in ES7/ES2016, does the sequential execution of multiple awaits mirror that of chaining .then() with promises? Specifically, will anotherCall() only commence upon the completion of someCall()?
Answer:
You have correctly interpreted the sequential nature of await.
Solution for Concurrent Execution:
To execute someCall() and anotherCall() concurrently, utilize Promise.all():
await Promise.all([someCall(), anotherCall()]);
Storing Results:
To capture the results, employ:
let [someResult, anotherResult] = await Promise.all([someCall(), anotherCall()]);
Note:
Keep in mind that Promise.all() fails promptly if any of its supplied promises reject.
The above is the detailed content of Does `async/await` Sequentially Execute Multiple `await` Calls Like Chained Promises?. For more information, please follow other related articles on the PHP Chinese website!