Tarun Telang
1 min readMar 30, 2020

--

I noticed incase of REST API calls the code below is not always taking care of sequence.

async function sequence() {
await promise1(50); // Wait 50ms…
await promise2(50); // …then wait another 50ms.
return “done!”;
}

Below code snippet looks more determisnistic to me as it ensure second promise is called only after first one is finished.

async function sequence() {
promise1(50).then(() => {
promise2(50);

});
return “done!”;
}

--

--

Tarun Telang
Tarun Telang

Written by Tarun Telang

Prolific Author, Engineering Leader, Software Architect

Responses (1)