Vow
Promises/A+ specification compatible promises library.
See https://github.com/promises-aplus/promises-spec.
Getting Started
###In the Node.js###
You can install using Node Package Manager (npm):
npm install vow
###In the Browsers###
<script type="text/javascript" src="vow.min.js"></script>
Also RequireJS module format supported.
API
####Vow.promise()####
Create promise
var promise = Vow.promise();
###Promise API###
####fulfill(value)####
Fulfill promise with given value
promise.fulfill(value);
####reject(reason)####
Reject promise with given reason
promise.reject(error);
####isFulfilled()####
Returns whether the promise is fulfilled
promise.isFulfilled();
####isRejected()####
Returns whether the promise is rejected
promise.isRejected();
####isResolved()####
Returns whether the promise is fulfilled or rejected
promise.isResolved();
####then([onFulfilled], [onRejected])####
Arranges for:
onFulfilled
to be called with the value after promise is fulfilled,onRejected
to be called with the rejection reason after promise is rejected.
Returns a new promise. See Promises/A+ specification for details.
promise.then(onFulfilled, onRejected);
####fail(onRejected)####
Arranges to call onRejected
on the promise's rejection reason if it is rejected.
####spread([onFulfilled], [onRejected])####
Like "then", but "spreads" the array into a variadic value handler.
###Vow API###
####isPromise(value)####
Returns whether the given value
is a promise.
####fulfill(value)####
Returns a promise that has already been fulfilled with the given value
. If value
is a promise, returned promise will be fulfilled with fulfill/rejection value of given promise.
####reject(reasonOrPromise)####
Returns a promise that has already been rejected with the given value
. If value
is a promise, returned promise will be rejected with fulfill/rejection value of given promise.
####resolve(value)####
Returns a promise that has already been fulfilled with the given value
. If value
is a promise, returns promise
.
####when(valueOrPromise, [onFulfilled], [onRejected])####
####all(promisesOrValues)####
####allResolved(promisesOrValues)####
####any(promisesOrValues)####
####timeout(promise, timeout)####