Async Await — Tricky

Deepika Gunda
1 min readSep 3, 2019

--

This will call multiple promises at one go .It will not wait for one value and then call another value.

const fruits = [‘peach’,’pineapple’,’strawberry’]const smoothie = fruits.map( async v => {

const f = await getFruit(v);
return f;
})
— — — — — — — — — — — — — —Async await with for loop
This will stop at every item in the iteration.
const fruitLoop = async() =>
{
for (const f of fruits)
{
let l = await getFruit(f);
console.log(l);
}
}
— — — — — — — — — — — — — — — — — —
For loop where it calls all the items concurrently.const fruits = [‘peach’,’pineapple’,’strawberry’]
const smoothie= fruits.map(v=> getFruit(v));
const fruitLoop = async() => {
for await (const l of smoothie)
{
}
}
if conditionalsconst fruitInspection = async()=>{
if(await getFruit(‘peach’)===’peach’)
{
do something .
}
}

--

--

Deepika Gunda

I am a Software Engineer n Tech Enthusiast . You will see me publishing articles on Javascript, NodeJS and misc.