Add callbackToPromise to util.ts
This commit is contained in:
parent
c9ccd2a937
commit
c6318cb8db
14
src/ts/util.ts
Normal file
14
src/ts/util.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue