Package detail

vow

dfilatov376.9kMIT0.4.20

DOM Promise and Promises/A+ implementation for Node.js and browsers

nodejs, browser, async, promise

readme

Vow NPM Version Build Status

NPM Downloads

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.

changelog

Changelog

0.4.18

0.4.17

  • Fixed an issue with wrong resolving after adding onProgress callback

0.4.16

0.4.15

0.4.14

0.4.13

  • Added workaround to avoid bug with Array.prototype.push in Opera 41

0.4.12

  • Wrong propagation of progress state fixed

0.4.11

  • Now global object (window, global) is passed properly

0.4.10

  • Now MutationObserver is used for internal "next tick" operations

0.4.9

  • vow.cast method was fixed to properly work with external promises #88

0.4.8

  • Detection of ymaps modular system was improved #82

0.4.7

  • vow.all had wrong behaviour in case of passing of another promise implementation #77
  • vow.timeout rejects with vow.TimedOutError instead of Error reason in case of timeout #76

0.4.6

  • defer.reject had wrong behaviour in case of already rejected promise was passed #72
  • CommonJS environment detection became more accurate #74

0.4.5

  • Throwing exceptions inside vow.reject was removed #69
  • promise.isFulfilled/promise.isRejected immediately return proper state of promise got from vow.fulfill(value)/reject(value) #68
  • Minor optimizations were added

0.4.4

  • ENB sources were added

0.4.3

  • Some optimizations for V8 were added #60. Thanks to B-Vladi.

0.4.2

  • Pass progress state from items in all arrays/objects methods #58

0.4.1

  • Improve detection of vow-compatible promises

0.4.0

  • Implement DOM Promise specification
  • Implement new Promise A+ specification
  • Remove promise.fulfill, promise.reject, promise.notify methods
  • Add vow.anyResolved method #53
  • Add vow.cast method #53

0.3.12

  • Make Promise class accessible from outside

0.3.11

  • Fix bug with inner timer in delay method #45

0.3.10

  • Use setImmediate instead of process.nextTick in Node.js >= 0.10.x #40
  • Up Promises/A+ Compliance Test Suite to 1.3.2

0.3.9

  • Fix for propagation of progress state #37

0.3.8

  • Fix for ignoring callback's context in always method #35
  • Callback in Vow.invoke called in global context now
  • bower.json added #34

0.3.7

  • Vow.allPatiently method added #32

0.3.6

  • Fix for properly work in mocha/phantomjs environment #31

0.3.5

  • Fix for synchronize onProgress callback in promise.sync method #30

0.3.4

  • Add ability to use multiple modules system simultaneously #26
  • Add callbacks to promise.done method #29

0.3.3

  • Use Vow instead this in all static methods
  • Speed up optimizations

0.3.2

  • Ability to specify context for callbacks #28

0.3.1

0.3.0

  • Add support for progress/notify #23

0.2.6

  • promise.always doesn't pass the return value of onResolved #19