function promisify(func, callbackPos=null) {
return (...args) => {
return new Promise((resolve) => {
const cb = (...args) => {
resolve(args);
};
args.splice(callbackPos != null ? callbackPos : args.length, 0, cb);
func(...args);
});
};
};