mammoth.js/lib/promises.js
2015-07-03 21:45:55 +01:00

26 lines
760 B
JavaScript

var _ = require("underscore");
var bluebird = require("bluebird/js/main/promise")();
exports.defer = bluebird.defer;
exports.when = bluebird.resolve;
exports.resolve = bluebird.resolve;
exports.all = bluebird.all;
exports.props = bluebird.props;
exports.reject = bluebird.reject;
exports.promisify = bluebird.promisify;
exports.nfcall = function(func) {
var args = Array.prototype.slice.call(arguments, 1);
var promisedFunc = bluebird.promisify(func);
return promisedFunc.apply(null, args);
};
bluebird.prototype.fail = bluebird.prototype.caught;
bluebird.prototype.also = function(func) {
return this.then(function(value) {
var returnValue = _.extend({}, value, func(value));
return bluebird.props(returnValue);
});
};