promises
broody-Broody implementation of Promises/A+.
Whats up?
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.
Getting started
Install with npm
npm install --save broody-promises
Overview
var promise chain; promise = { // resolve now synchronous ; }; chain = Promise; chain; // my value!
API
resolver
: Function(resolve: Function(value: any), reject: Function(reason: any)
))
new Promise(onResolve
: Function(value: any)
, onReject
: Function(reason: any)
) -> Promise
promise.then(onReject
: Function(reason: any)
) -> Promise
promise.catch(anyWay
: Function(error: any, value: any)
) -> Promise
promise.finally(any
promise.result() -> Returns resolved value.
Throws an error in two cases:
- target promise is in
pending
state. - target promise was rejected.
Boolean
promise.isPending() -> Boolean
promise.isFulfilled() -> Boolean
promise.isRejected() -> fn
: Function()
) -> any
Promise.sync(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 .value()
method.
Note, that with this feature, Broodies will not pass the 2.2.4 rule of the Promises/A+ spec.
promises
: Array[Promise]
) -> Promise
Promise.all(value
: any
) -> Promise
Promise.resolve(Returns new resolved Promise.
error
: any
) -> Promise
Promise.reject(Returns new rejected Promise.