Hacker News new | past | comments | ask | show | jobs | submit login

Can you give an example of more fine grained control with then?



Often times operations are order-independent. Specifying those as sequential `await`-s does not make a lot of sense in those situations. I guess less fine grained control is desirable under such circumstances :-)

There's also other useful utilities such as Promise.all(), Promise.any() and Promise.race().


const [result1, result3] = await Promise.all([task1(), task2.then(res => task3(res))])


Could that be written

  const task2then3 = async () => task3(await task2());
  const [result1, result3] = await Promise.all([task1(), task2then3()])


I'd just:

    async function getResult3(){
      const res = await task2()
      return task3(res))
    }

    const [result1, result3] = await Promise.all([task1(), 
    getResult3()])




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: