3 ms·
What if you want to abort, or take another path, depending on an error code ? With callbacks there's a convention that the first parameter is either null or an
by z3t4 9y ago
What if you want to abort, or take another path, depending on an error code ? With callbacks there's a convention that the first parameter is either null or an error.
- Mitranim 9y agoThat's what the mapping operators are for: `.mapResult` (same as `promise.then`), `.mapError` (same as `promise.catch`), or `.map`. The latter has an errback signature, like Node.js callbacks. They can also return new futures, transforming the result asynchronously. On top of that, error handling in promises/futures is much easier than in callbacks, as you can use one error handler for a chain of operations. Kinda like exceptions in synchronous code.