diff --git a/util/src/util_js.ts b/util/src/util_js.ts index c3f91ac13bd9a3bc1aa6bd014025d970112fc1cd..1f514eb9c408382704df0f15f63291abeef10619 100644 --- a/util/src/util_js.ts +++ b/util/src/util_js.ts @@ -441,7 +441,23 @@ function callbackWrapper(original : Fn) : void Object.defineProperties(cb, descriptors); } -function promiseWrapper(func : Function) : Function +function promiseWrapper(func : Function) : Object +{ + return function (...args : Array) { + return new Promise((resolve, reject) => { + let callback : Function = function (err : Object | string, ...values : Array) { + if (err) { + reject(err); + } else { + resolve(values); + } + }; + func.apply(null, [...args, callback]); + }); + }; +} + +function promisify(func : Function) : Function { return function (...args : Array) { return new Promise((resolve, reject) => { @@ -1012,6 +1028,7 @@ export default { getErrorString: getErrorString, callbackWrapper: callbackWrapper, promiseWrapper: promiseWrapper, + promisify: promisify, createExternalType: createExternalType, TextEncoder: TextEncoder, TextDecoder: TextDecoder,