mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
See explanation: https://github.com/EmergingTechnologyAdvisors/node-serialport/issues/1245 Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
23 lines
445 B
JavaScript
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
|
|
};
|