diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-07-03 21:45:55 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-07-03 21:45:55 +0100 |
| commit | cd3b84e15ea1a47ff8ebcca18d68ef0cdccf20b8 (patch) | |
| tree | 46c9fbd816c26116fbc36e7578b763162050d69a /lib/promises.js | |
| parent | 792aa9fb8cab1b68c585f09336758e2c76e3e8d5 (diff) | |
Add also function as a lesser evil to avoid callback hell
Diffstat (limited to 'lib/promises.js')
| -rw-r--r-- | lib/promises.js | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/promises.js b/lib/promises.js index 747bc5b..4c10285 100644 --- a/lib/promises.js +++ b/lib/promises.js @@ -1,9 +1,11 @@ +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; @@ -14,3 +16,10 @@ exports.nfcall = function(func) { }; 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); + }); +}; |
