Created
January 10, 2019 11:35
-
-
Save Alex1990/28c461c43ed46c40a33a742d900ce0b5 to your computer and use it in GitHub Desktop.
Like Node.js util.promisify
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(func) { | |
return (...args) => { | |
const args1 = args.slice(0, args.length); | |
return new Promise((resolve, reject) => { | |
const callback = (err, ...rest) => { | |
if (err) { | |
reject(err); | |
} else { | |
resolve(...rest); | |
} | |
}; | |
func(...args, callback); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment