JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.5.1/bluebird.min.js"></script>
JavaScript
//does NOT run in paralel, blocking behavior
const test1 = async () => {
const time1 = new Date().getTime();
const delay1 = await Promise.delay(600); //runs 1st
const delay2 = await Promise.delay(600); //waits for delay1 to run
const delay3 = await Promise.delay(600); //waits for delay2 to run
const time2 = new Date().getTime();
console.log('result 1: ', time2 - time1);
};
//runs in paralel, async behavior
const test2 = async () => {
const time1 = new Date().getTime();
const delay1 = Promise.delay(600);
const delay2 = Promise.delay(600);
const delay3 = Promise.delay(600);
const data1 = await delay1;
const data2 = await delay2;
const data3 = await delay3;
const time2 = new Date().getTime();
console.log('result 2: ', time2 - time1);
}
//runs in paralel, async behavior
const test3 = async () => {
const time1 = new Date().getTime();
await Promise.all([Promise.delay(600), Promise.delay(600), Promise.delay(000)]);
const time2 = new Date().getTime();
console.log('result 3: ', time2 - time1);
};
test1();
test2();
test3();