UNPKG

es-promise-ext

Version:

Native promise extensions for javascript and typescript.

26 lines (25 loc) 1.1 kB
import { AsyncFunction } from './retry'; declare global { interface Promise<T> { /** * Starts a promise with an asynchronous function that has retry tolerance. * * @param {AsyncFunction<U> | Promise<U>} asyncFunction * - An asynchronous function that will be called, returning a result in a promise. * @param {number} [count=3] * - A positive integer between 0 and 30 indicating the number of retries. * @param {number} [delay=100] * - The time in milliseconds to wait between retries. * * @return {Promise<U>} * The function wrapper of return the result within a promise after retries. * * @example * Promise.resolve().retry(asyncFunction, 5, 1000); * Promise.resolve().retry(() => asyncFunction(1, 2), 5, 1000); * Promise.resolve().retry(promise, 5, 1000); * // Retry 5 times with a 1-second interval. */ retry<U>(asyncFunction: AsyncFunction<U> | PromiseLike<U>, count: number, delay: number): Promise<U>; } }