Skip to content

Instantly share code, notes, and snippets.

@RReverser
Last active September 15, 2015 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RReverser/79afe3bfacbe054264d6 to your computer and use it in GitHub Desktop.
Save RReverser/79afe3bfacbe054264d6 to your computer and use it in GitHub Desktop.
function awaitableVersionOf(nodeFunction) {
return (...args) => new Promise((resolve, reject) => {
nodeFunction(
...args,
(error, ...cbArgs) => error ? reject(error) : resolve(...cbArgs)
);
});
}
@RickWong
Copy link

Does it matter much to the nodeFunction that you're using => for all the closures instead of function()?

@RReverser
Copy link
Author

I don't think so. Are you aware of any node.js lib that cares about result of callback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment