Skip to content

Instantly share code, notes, and snippets.

@dunstontc
Created June 23, 2017 19:25
Show Gist options
  • Save dunstontc/8328efc091835222bcf63778bac88158 to your computer and use it in GitHub Desktop.
Save dunstontc/8328efc091835222bcf63778bac88158 to your computer and use it in GitHub Desktop.
'use strict';
module.exports = (fn) => {
return function () {
const length = arguments.length;
const args = new Array(length);
for (let i = 0; i < length; i += 1) {
args[i] = arguments[i];
}
return new Promise((resolve, reject) => {
args.push((err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
fn.apply(null, args);
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment