Hacker News new | ask | show | jobs
by peq 2535 days 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.
1 comments

That'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.
Promises 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()]);
Whoops, you're right! I hadn't thought it through.