/ c4f / front / node_modules / exponential-backoff /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]dist/8 months ago -  
[   ]LICENSE8 months ago 11K 
[TXT]README.md8 months ago2.4K 
[   ]package.json8 months ago1.3K 
README.md

exponential-backoff

A utility that allows retrying a function with an exponential delay between attempts.

Installation

npm i exponential-backoff

Usage

The backOff<T> function takes a promise-returning function to retry, and an optional BackOffOptions object. It returns a Promise<T>.

function backOff<T>(
  request: () => Promise<T>,
  options?: BackOffOptions
): Promise<T>;

Here is an example retrying a function that calls a hypothetical weather endpoint:

import { backOff } from "exponential-backoff";

function getWeather() {
  return fetch("weather-endpoint");
}

async function main() {
  try {
    const response = await backOff(() => getWeather());
    // process response
  } catch (e) {
    // handle error
  }
}

main();

Migrating across major versions? Here are our breaking changes.

BackOffOptions

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80