News for hackers. Stuff that matters.
Re:Request’s Past, Present and Future by tlrobinson on Monday April 08, 2019 @12:01PM (#19606412)
When you add asynchronous operations, whether they use promises or callbacks, they tend to spread beacause any consumer of an async operation probably needs to be async itself. That’s not specific to promises.

If you return a promise you don’t really need to support a callback because you can just call .then on the promise with a callback. i.e.

    func().then(result => {
      // success
    }, err => {
      / error
    })
Is equivalent to

    func((err, result) => {
      if (err) {
        // error
      } else {
        // success
      }
    })
IMHO promise-based APIs are strictly better than callback/“errback” style APIs for many reasons, async/await support in the language being the nail in the coffin.

There are no comments on this comment yet.