module-promise
v0.1.2
Published
DOM Promise and Promises/A+ implementation for Node.js and browsers
Downloads
3
Maintainers
Readme
Module Promise
Getting Started
Install with NPM
$ npm install module-promise
Install with Bower
$ bower install module-promise
In Browsers
<script type="text/javascript" src="promise.min.js"></script>
Usage
// Node.js
var Promise = require('module-promise');
// Global Window in Browsers
var Promise = Core.Promise;
// RequireJS
require('Core.Promise', function(Promise){
// do something
});
// Yandex modules
modules.require('Core.Promise', function(Promise){
// do something
});
new Promise(resolver)
var doSomethingAsync = new Promise(function(resolve, reject, notify){
// resolve('ok');
// reject(new Error('Custom error'));
// notify('val');
});
doSomethingAsync.then(
function() {}, // onResolved
function() {}, // onRejected
function() {} // onNotified
);
Promise.defer
function doSomethingAsync() {
var deferred = Promise.defer();
// deferred.resolve('ok');
// deferred.reject(new Error('Custom error'));
// deferred.notify('val');
return deferred.promise;
}
doSomethingAsync().then(
function() {}, // onResolved
function() {}, // onRejected
function() {} // onNotified
);
License
The Promise module is open-sourced software licensed under the MIT license.