Skip to content

Instantly share code, notes, and snippets.

@cdhowie
Created April 13, 2017 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdhowie/cdeb0c05e335ca5944e599b6a91b8a1a to your computer and use it in GitHub Desktop.
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.)
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