i'd like to know how can i beautify a code snippet in javascript, which Looks like that
async sequenceOfFunctionCalls () {
await callFunction1();
await callFunction2();
...
await callFunctionN();
}
Assuming you want to run them in sequence (not in parallel), I'd say the simplest option is:
for (let func of [callFunction1, callFunction2, ..., callFunctionN]) {
await func();
}
To run them in parallel:
await Promise.all([callFunction1, callFunction2, ..., callFunctionN].map(f => f()));
or
await Promise.allSettled([callFunction1, callFunction2, ..., callFunctionN].map(f => f()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With