Add callbackToPromise to util.ts

This commit is contained in:
Nick Krichevsky 2018-07-24 01:33:17 -04:00
parent c9ccd2a937
commit c6318cb8db

14
src/ts/util.ts Normal file
View file

@ -0,0 +1,14 @@
/**
* callbackToPromise converts a callback based function to a promise based function.
* The function's only argument must be a function.
*
* @param {(Function) => void} func
* @returns {PromiseLike<any[]>}
*/
export function callbackToPromise(func: (Function) => void): PromiseLike<any[]> {
return new Promise((resolve) => {
func((...callbackArgs) => {
resolve(callbackArgs);
});
});
}