News for hackers. Stuff that matters.
Re:JavaScript Promises Discussion: Make Them Monadic? (2013) by sushid on Thursday February 15, 2018 @07:15PM (#16388939)
I started programming professionally around the same time but I'm surprised that you think Promise.all([]) makes things easy. IMO Promise.all([]) is nice until you start supporting proper error handling.
Re:JavaScript Promises Discussion: Make Them Monadic? (2013) by nawgszy on Friday February 16, 2018 @02:31PM (#16395219)
I'm not sure what you're getting at, can you expand?

I work a lot with databases, so say you're trying to write an object and its children in some sort of one-to-many relationship to the DB.

You can write a Promise chain like

  startTransaction()
  .then(() => writeParent())
  .then((children) =>
    Promise.all(children.map((child) =>
      writeChild(child)
    ))
  )
  .then(
    // handle success
    endTransaction(),
    // handle error
    cancelTransaction()
  )
What exactly about that isn't "proper error handling"? Can you expand a bit on how this would be handled differently by you, or perhaps what paradigm you're programming in where Promise.all executes a bunch of items that can't all have the same success and error handler?