Skip to content

Instantly share code, notes, and snippets.

@tchar
Last active February 16, 2018 18:24
Show Gist options
  • Save tchar/8352adbb90a0e332fd0288534de1870c to your computer and use it in GitHub Desktop.
Save tchar/8352adbb90a0e332fd0288534de1870c to your computer and use it in GitHub Desktop.
Promisify a function
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