Last active
April 24, 2017 11:07
-
-
Save remmycat/96d94011bbedb85882c49dfdd04bc698 to your computer and use it in GitHub Desktop.
Promisifying callback-oriented nodejs libs with ES6 (example)
This file contains 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
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