News for hackers. Stuff that matters.
Re:A Modern JavaScript Tutorial by golergka on Monday December 07, 2020 @12:26PM (#25334360)
async/await is excellent syntax when you want things to happen one after another. That's the usual case, and that's what I find myself using 95% of the time.

However, when you want a more fine-grained concurrent execution of different asynchronous things, then() still could be very useful.

Re:A Modern JavaScript Tutorial by postalrat on Monday December 07, 2020 @01:16PM (#25335101)
Can you give an example of more fine grained control with then?
Re:A Modern JavaScript Tutorial by wa1987 on Monday December 07, 2020 @01:44PM (#25335492)
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().

Re:A Modern JavaScript Tutorial by golergka on Monday December 07, 2020 @01:40PM (#25335448)
const [result1, result3] = await Promise.all([task1(), task2.then(res => task3(res))])
Re:A Modern JavaScript Tutorial by postalrat on Monday December 07, 2020 @02:43PM (#25336281)
Could that be written

  const task2then3 = async () => task3(await task2());
  const [result1, result3] = await Promise.all([task1(), task2then3()])
Re:A Modern JavaScript Tutorial by nailer on Tuesday December 08, 2020 @06:29AM (#25343982)
I'd just:

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

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