Parallel, sequence and Race
const promisify = (item, delay) =>
new Promise((resolve) =>
setTimeout(() =>
resolve((item), delay));
const a = () => promisify('a', 100);
const b = () => promosify('a', 5000);
const c = () => promisify('c', 3000);
=> I want you to do all the promises at the same timeasync function parallel(() =>
const promises[a(), b(), c()];
const [output1, output2, output3] = await Promise.all(promises);
return `Parallel is done: ${output1} ${output2} ${outpt3}`
}
=> whatever is fastest just returnasync function race() {
const promises[a(), b(), c()];
const output1 = await Promise.race(promises);
return `Race is done: $[output1};
}
=> wait for each promise and do sequentiallyasync function sequence() {
const output1 = await a();
const output2 = await b();
const output3 = await c();
return `Sequence is done: ${output1} ${output2} ${outpt3}`;
}