7 ms·
It's easy to run tasks in parallel with just "await". Just start your tasks without await, store the promise in a variable, and then use await later when you ac
by peq 7y ago
It's easy to run tasks in parallel with just "await". Just start your tasks without await, store the promise in a variable, and then use await later when you actually need the value.
- pault 7y agoThat's fine, but you'll still only be able to block on one promise at a time. If you want to wait until all promises have resolved you still have to use Promise. all.
- Nullabillity 7y agoPromises are started eagerly, so const xP = getX(); const yP = getY(); const x = await xP; const y = await yP; is just as parallel as const [x, y] = Promise.all([getX(), getY()]);
- pault 7y agoWhoops, you're right! I hadn't thought it through.