es-promise-ext
Version:
Native promise extensions for javascript and typescript.
21 lines (20 loc) • 817 B
TypeScript
/**
* Starts a promise with an asynchronous function that use a callback.
*
* @param {WrappedAsyncFunction<U>} wrappedAsyncFunctionWithCallback
* - An asynchronous function that will be called, returning a result in callback.
*
* @return {Promise<U>}
* The result returned from callback.
*
* @example
* promiseWrap(asyncFunction);
* // for asyncFunction accepting the callback as 1st parameter
*
* promiseWrap(cb => asyncFunction(1, 2, cb));
* // for other asyncFunction accepting the callback as the rest parameter
*/
export default function wrap<U extends any[]>(wrappedAsyncFunctionWithCallback: WrappedAsyncFunction<U>): Promise<U>;
type CallbackFunction<U extends any[]> = (...args: U) => any;
export type WrappedAsyncFunction<U extends any[]> = (callback: CallbackFunction<U>) => any;
export {};