Skip to content

Instantly share code, notes, and snippets.

@remmycat
Last active April 24, 2017 11:07
Show Gist options
  • Save remmycat/96d94011bbedb85882c49dfdd04bc698 to your computer and use it in GitHub Desktop.
Save remmycat/96d94011bbedb85882c49dfdd04bc698 to your computer and use it in GitHub Desktop.
Promisifying callback-oriented nodejs libs with ES6 (example)
export default function getPromiseLib(lib) {
return new Proxy(lib, {
get: (target, prop) => (...args) =>
new Promise((resolve, reject) => {
target[prop](...args, (err, ...params) => {
if (err) {
reject(err);
} else {
resolve(params);
}
});
}),
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment