#promiseback
Accept an optional node-style callback, and also return a spec-compliant Promise!
API
var promiseback = require('promiseback');
var callback = function (err, value) {};
promiseback(callback);
promiseback(promise, callback);
Examples
Using deferreds:
var promiseback = require('promiseback');
module.exports = function doSomethingCool(thing, callback) {
var deferred = promiseback(callback);
if (thing) {
deferred.resolve(thing);
} else {
deferred.reject(thing);
}
return deferred.promise;
};
Using a straight promise, when you can get it from somewhere else:
var promiseback = require('promiseback');
module.exports = function doSomethingCool(thing, callback) {
var newThingPromise = makeNewThing(thing);
return promiseback(newThingPromise, callback);
};
Tests
Simply clone the repo, npm install
, and run npm test