1function promisify(func, callbackPos=null) {
2 return (...args) => {
3 return new Promise((resolve) => {
4 const cb = (...args) => {
5 resolve(args);
6 };
7 args.splice(callbackPos != null ? callbackPos : args.length, 0, cb);
8 func(...args);
9 });
10 };
11};