Socket
Socket
Sign inDemoInstall

vow

Package Overview
Dependencies
10
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vow

Promises/A+ proposal compatible promises library


Version published
Weekly downloads
75K
decreased by-24.27%
Maintainers
1
Install size
1.21 MB
Created
Weekly downloads
 

Readme

Source

Vow Build Status

Promises/A+ implementation. 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

var promise = Vow.promise();
promise.fulfill('completed'); // fulfill promise with 'completed' value

####reject(reason)#### Reject promise with given reason

var promise = Vow.promise();
promise.reject(Error('internal error')); // reject promise with Error object

####isFulfilled()#### Returns whether the promise is fulfilled

var promise = Vow.promise();
promise.isFulfilled(); // returns false
promise.fulfill('completed');
promise.isFulfilled(); // returns true

####isRejected()#### Returns whether the promise is rejected

var promise = Vow.promise();
promise.isRejected(); // returns false
promise.reject(Error('internal error'));
promise.isRejected(); // returns true

####isResolved()#### Returns whether the promise is fulfilled or rejected

var promise = Vow.promise();
promise.isResolved(); // returns false
promise.fulfill('completed'); // or promise.reject(Error('internal error'));
promise.isResolved(); // returns true

####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.

var promise = Vow.promise();
promise.then(
    function() { // to be called after promise is fulfilled
    },
    function() {// to be called after promise is rejected        
    });

####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.

promise.spread(onFulfilled, onRejected);

###Vow API###

####when(value, [onFulfilled], [onRejected])#### Static equivalent for promise.then. If given value is not a promise, value is equivalent to fulfilled promise.

####isPromise(value)#### Returns whether the given value is a promise.

Vow.isPromise('value'); // returns false
Vow.isPromise(Vow.promise()); // returns true

####isFulfilled(value)#### Returns whether the given value is fulfilled. If value is not a promise, value is equivalent to fulfilled promise.

####isRejected(value)#### Returns whether the given value is rejected. If value is not a promise, value is equivalent to fulfilled promise.

####isResolved(value)#### Returns whether the given value is resolved (fulfilled or rejected). If value is not a promise, value is equivalent to fulfilled 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(reason)#### Returns a promise that has already been rejected with the given reason. If reason 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.

####all(promises)#### Returns a promise to be fulfilled only after all the items in promises is fulfilled, or to be rejected when the first promise is rejected.

####allResolved(promises)#### Returns a promise to be fulfilled only after all the items in promises is resolved.

####any(promises)#### Returns a promise to be fulfilled only any item in promises is fulfilled, or to be rejected when the all items is rejected.

####timeout(promise, timeout)#### Returns a promise to be rejected after a timeout if promise does not resolved beforehand.

Keywords

FAQs

Last updated on 25 Dec 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc