3 ms·
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
by tlrobinson 8y ago
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.