then-catch v0.0.1
WIP
Intro
While there are bunch of Promise helpers out there, one may feel things are not suite the case, or it's kind of bloated, or place any reason here. Rather than reinventing the wheel, although, this library comes with several Promise helper methods which already offered by any Promise libraries on this planet, some of those methods are actually have a slightly different behavior. Other than that, this library also built with micro-optimization in mind.
Installation
npm i -S then-catch
Usage
ThenCatch extends native Promise by default.
const tc = require('then-catch')
tc.resolve(42)
.then(results => results)
.catch(err => {
console.error('U WOT M8', err.stack)
})
If you already using a Promise library such as the mighty Bluebird, assign it to use
method while require
ing.
const Bluebird = require('bluebird')
const tc = require('then-catch').use(Bluebird)
tc.sequence([someFn, anotherFn, yetAnotherFn])
.each(inspection => {
if (inspection.isFulfilled()) {
console.log('I am fulfilled', inspection.value());
} else {
console.error('am done with you', inspection.reason());
}
})
NOTE: Some methods has same name with any existing Promise libraries, thus will be overriden and will exactly has different behaviour than expected.
Test
Find more examples or run some test, checkout the test directory or run,
npm test
License
8 years ago