promise-native-deferred
v3.0.0
Published
A lightweight Deferred implementation, using native Promises
Downloads
742
Maintainers
Readme
promise-native-deferred
This is a fork of promise-deferred, but instead uses the environment's native Promise implementation instead of a polyfill. This means that browser tools won't unnecessarily bundle a Promise polyfill when one already exists or Promise is provided natively.
Usage
var deferred = new Deferred()
In order to use this module in environments without Promises, either polyfill ahead-of-time
or pass your custom Promise
during Deferred construction like so:
var deferred = new Deferred(MyPromise)
or simply:
var deferred = Deferred(MyPromise)
A lightweight Deferred implementation, on top of Promises/A+
Examples
var Deferred = require('promise-deferred');
var deferred = new Deferred();
// set up handlers
deferred.promise.then(function (value) {}, function (error) {});
// resolve
deferred.resolve('a value');
// reject
deferred.reject(new Error('oh noes'));
Tests
Simply clone the repo, npm install
, and run npm test