Skip to content

Function: retry()

ts
function retry<T>(factory, options?): Promise<T>;

Retries an async factory on failure.

Type Parameters

Type Parameter
T

Parameters

ParameterType
factory() => Promise<T>
optionsRetryOptions

Returns

Promise<T>

Example

ts
let attempts = 0
const result = await retry(async () => {
  attempts++
  if (attempts < 3) throw new Error('not yet')
  return 'success'
}, { times: 3, delay: 0 })
result // => 'success'
attempts // => 3

Since

1.0.0

Released under the MIT License.