const promisify = func => {
// this need to not using arrow function, otherwise the this context will be wrong
return function() {
const args = Array.from(arguments);
return new Promise((resolve, reject) => {
const callback = (err, data) => {
if (error) {
return reject(err);
}
return resolve(data);
};
args.push(callback);
func.apply(this, args);
});
};
}
API.someAsyncFunc = promisify(someAsyncFunc)
RE: CSC v1