Created
April 13, 2017 13:53
-
-
Save cdhowie/cdeb0c05e335ca5944e599b6a91b8a1a to your computer and use it in GitHub Desktop.
Simple shim for promise-nodecb interop without requiring a full-blown promise library. (Useful as a boilerplate for AWS Lambda functions.)
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
Promise.fromCallback = fn => | |
new Promise((r, j) => { | |
fn((err, result) => err ? j(err) : r(result)); | |
}); | |
Promise.prototype.nodeify = function (cb) { | |
cb && this.then(r => cb(null, r), cb); | |
return cb ? undefined : this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment