reretry
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Retry

Retry failed operations using exponential backoff.

Example

import { retry } from 'reretry';

const result = await retry(async (again) => {
  const response = await fetch('https://example.com')

  if (!response.ok)
    return again // retry
  else
    return response.json()
}, {
  attempts: Infinity,
  base: 1000,
  max: 30000,
  factor: 1.5,
  dispersion: 0.1
})

Options

  • attempts - maximum number of attempts to retry, throws an error if exceeded. Default: Infinity.
  • base - base delay in milliseconds. Default: 1000.
  • max - maximum delay in milliseconds. Default: 30000.
  • factor - exponential factor. Default: 1.5.
  • dispersion - randomization factor. Default: 0.1.

Readme

Keywords

Package Sidebar

Install

npm i reretry

Weekly Downloads

26

Version

0.1.0

License

MIT

Unpacked Size

47.2 kB

Total Files

15

Last publish

Collaborators

  • agurtovoi