Async Await Concurrent execution
JS
S
JavaScriptAsync Await concurrent execution of promises. Avoid sequencing async() await operations as they are not concurrent and the performance of your app will decrease.
1// Sample Example
2const sendRequest = (item) => {
3 // do stuff
4 return new Promise((resolve, reject) => {
5 resolve();
6 });
7});
8
9async function processItems() {
10 const items = await getItems() // async call
11 const promises = items.map((item) => sendRequest(item))
12 await Promise.all(promises) // async call
13}
14
15processItems()
16.then((result) => {
17
18})Created on 6/17/2018