node-serialport-bindings-cpp/lib/util.js
2017-07-21 14:44:06 -04:00

23 lines
445 B
JavaScript

'use strict';
function promisify(func) {
if (typeof func !== 'function') {
throw new Error('"func" must be a function');
}
return function() {
const args = Array.from(arguments);
return new Promise((resolve, reject) => {
args.push((err, data) => {
if (err) {
return reject(err);
}
resolve(data);
});
func.apply(null, args);
});
};
}
module.exports = {
promisify
};