UNPKG

es-promise-ext

Version:

Native promise extensions for javascript and typescript.

22 lines (21 loc) 857 B
/** * Starts a promise with an asynchronous function that has retry tolerance. * * @param {AsyncFunction<T> | Promise<T>} 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<T>} * The result within a promise after retries. * * @example * promiseRetry(asyncFunction, 5, 1000); * promiseRetry(() => asyncFunction(1, 2), 5, 1000); * promiseRetry(promise, 5, 1000); * // Retry 5 times with a 1-second interval. */ export default function retry<T>(asyncFunction: AsyncFunction<T> | PromiseLike<T>, count?: number, delay?: number): Promise<T>; export type AsyncFunction<T> = () => Promise<T>;