Last active
February 16, 2018 18:24
-
-
Save tchar/8352adbb90a0e332fd0288534de1870c to your computer and use it in GitHub Desktop.
Promisify a function
This file contains hidden or 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(func, context) { | |
return function(...p) { | |
return new Promise(function(resolve, reject) { | |
p.push(function(err, data) { | |
if (err) { | |
reject(err) | |
} else { | |
resolve(data) | |
} | |
}) | |
func.apply(context, p) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment