Giter VIP home page Giter VIP logo

vow's Introduction

Vow NPM version Build Status

Vow is a Promises/A+ implementation. It also supports ES6 Promises specification.

Full API reference can be found at http://dfilatov.github.io/vow/.

Getting Started

In Node.js

You can install using Node Package Manager (npm):

npm install vow

In Browsers

<script type="text/javascript" src="vow.min.js"></script>

It also supports RequireJS module format and YM module format.

Vow has been tested in IE6+, Mozilla Firefox 3+, Chrome 5+, Safari 5+, Opera 10+.

Usage

Creating a promise

There are two possible ways to create a promise.

1. Using a deferred

function doSomethingAsync() {
    var deferred = vow.defer();
    
    // now you can resolve, reject, notify corresponging promise within `deferred`
    // e.g. `defer.resolve('ok');`
        
    return deferred.promise(); // and return corresponding promise to subscribe to reactions
}

doSomethingAsync().then(
    function() {}, // onFulfilled reaction
    function() {}, // onRejected reaction
    function() {}  // onNotified reaction
    );

The difference between deferred and promise is that deferred contains methods to resolve, reject and notify corresponding promise, but the promise by itself allows only to subscribe on these actions.

2. ES6-compatible way

function doSomethingAsync() {
    return new vow.Promise(function(resolve, reject, notify) {
        // now you can resolve, reject, notify the promise
    });
}

doSomethingAsync().then(
    function() {}, // onFulfilled reaction
    function() {}, // onRejected reaction
    function() {}  // onNotified reaction
    );

Extensions and related projects

  • vow-fs — vow-based file I/O for Node.js
  • vow-node — extension for vow to work with nodejs-style callbacks
  • vow-queue — vow-based task queue with weights and priorities
  • vow-asker — wraps asker API in the vow promises implementation

NOTE. Documentation for old versions of the library can be found at https://github.com/dfilatov/vow/blob/0.3.x/README.md.

vow's People

Contributors

dfilatov avatar dimik avatar vs-kurkin avatar dodev avatar golyshevd avatar alexeyten avatar thekashey avatar mdevils avatar marcodejongh avatar markelog avatar tworoger avatar ikokostya avatar

Watchers

James Cloos avatar Josh Raymond avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.