by petepete · 9y ago · 0 comments
const a = taskA();
const b = taskB();
const c = taskC();
const result = [await a, await b, await c];Your version guarantees the three are executed before moving forward. The order may differ on each run.
The implementation of Promise.all could use one array for results and fill it in any order as soon as any promise resolves while awaits will always proceed in strict order (like a generator). But that's an implementation detail that a JS programmer doesn't need to think about.
edit: just checked and your version is indeed parallel. Interesting.
I still typically prefer Promise.all though. It's a bit more obvious what's going on (IMO) and you can skip the additional lines for assigning the promises to variables.