Created
December 12, 2016 23:41
-
-
Save devsnek/9eab7bcc01eef7656eb899a94effc46a to your computer and use it in GitHub Desktop.
also here's a promisify that blows bluebird out of the water.
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
function promisify (fn, thisArg = null) { | |
return (...args) => { | |
return new Promise((resolve, reject) => { | |
const callback = (err, res) => { | |
if (err) return reject(err); | |
return resolve(res); | |
} | |
fn.apply(thisArg, [...args, callback]); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment