UNPKG

es-promise-ext

Version:

Native promise extensions for javascript and typescript.

23 lines (22 loc) 873 B
import { WrappedAsyncFunction } from './wrap'; declare global { interface PromiseConstructor { /** * 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 * Promise.wrap(asyncFunction); * // for asyncFunction accepting the callback as 1st parameter * * Promise.wrap(cb => asyncFunction(1, 2, cb)); * // for other asyncFunction accepting the callback as the rest parameter */ wrap<U extends any[]>(wrappedAsyncFunctionWithCallback: WrappedAsyncFunction<U>): Promise<U>; } }