broody-promises
Broody implementation of Promises/A+.
Broody promises is a minimalistic lightweight (~1.5KB gzipped) implementation of Promises/A+, with ability to retrieve fulfilled value. Of course, it is possible to do that just when all chain of thens and catchs are resolved synchronous. In other way usage of Broodies did not make any sense to you, because it has no any preferences over already existing and great Promises/A+ libraries.
Install with npm
npm install --save broody-promises
var promise, chain;
promise = new Promise(function(resolve, reject) {
// resolve now synchronous
resolve("my value");
});
chain = Promise.sync(function() {
return promise
.then(function(value) {
// again synchronous
return value + "!";
});
});
chain.result(); // my value!
Returns resolved value.
Throws an error in two cases:
- target promise is in
pending
state. - target promise was rejected.
Enters in a new context with given functon, when any new Promise
(created synchronously) will have synchronous resolution of onFulfilled
and onRejected
callbacks in .then
chains. This brings ability to use .result()
method.
Note, that with this feature, Broodies will not pass the 2.2.4 rule of the Promises/A+ spec.
Returns new resolved Promise.
Returns new rejected Promise.