Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Created January 10, 2019 11:35
Show Gist options
  • Save Alex1990/28c461c43ed46c40a33a742d900ce0b5 to your computer and use it in GitHub Desktop.
Save Alex1990/28c461c43ed46c40a33a742d900ce0b5 to your computer and use it in GitHub Desktop.
Like Node.js util.promisify
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