• Retries a single task up to times times, with a delay of delayms between each attempt.

    If times is zero, it repeats until it is successful

    Returns when an attempt at a task is successful

    Example

    // A task with a 1s timeout
    const task = Promise.race([() => getResource('foo'), new Promise((_,rej) => setTimeout(rej,1000))]);
    retry(() => getResource('foo').timeout(1000), 5)
    .then(useResource);

    This will attempt to get foo up to 5 times. It will stop trying when it gets it.

    Returns

    Type Parameters

    • R

    Parameters

    • task: Task<R, []>

      the Task to keep trying

    • times: number = 0

      the number of times to keep trying; defaults to 0 which means keep trying until successful

    • delay: number = 0

      the number of milliseconds to wait between tries; defaults to no wait

    Returns Promise<null | R>

Generated using TypeDoc