Last active
February 24, 2016 20:18
-
-
Save jakemcgraw/db3b3bbd601499931f50 to your computer and use it in GitHub Desktop.
Pattern for blue compatible modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modules.export = (function(){ | |
var Promise = require('bluebird'); | |
var fs = Promise.promisifyAll(require('fs')); | |
return function(params, cb) { | |
return fs.doSomeStuffAsync(params) | |
.then(function(result){ | |
return someOtherAsync(result); | |
}) | |
.then(function(moreResults){ | |
return someMoreAsync(moreResults); | |
}) | |
.finally(cb || function(){ }); | |
}; | |
})(); | |
Thanks for advice! Working it in now
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks real good! I think usually the client worries about error handling, and Bluebird.prototype.asCallback is your friend here! :)
Now it can be consumed like