promise-resolver
Turn a promises resolver methods into a node style callback
Install
$ npm install --save promise-resolver
Usage
var promiseResolver = require('promise-resolver');
new Promise(function (resolve, reject) {
var cb = promiseResolver(resolve, reject, passThroughCallback);
cb(new Error('...'));
cb(null, 'result');
});
API
promiseResolver(resolve, reject, passThrough)
All arguments should be functions, null, or undefined.
resolve
- promise resolve functionreject
- promise reject functionpassThrough
- a "pass through" node style (error first) callback.
Returns a node style callback: cb(err, result...)
Calling the callback will resolve or reject the promise (depending on the err
argument).
If it exists, the passThrough
callback will be called with the same arguments.
promiseResolver.defer(passThrough, Promise)
passThrough
- a "pass through" node style callback as described abovePromise
- an alternate Promise constructor (will use global.Promise
by default).
The return value is a standard defer
object with an additional cb
property
that is a node style resolver callback.
var defer = promiseResolver(passThroughCallback);
var cb = defer.cb;
cb(new Error('...'));
cb(null, 'result');
return defer.promise;
defer.resolve
, and defer.reject
are also available on the defer object.
License
MIT © James Talmage