Skip to content

Instantly share code, notes, and snippets.

@remmythical

remmythical/promiseLib.js

Last active Apr 24, 2017
Embed
What would you like to do?
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