/ student-intifada / node_modules / exponential-backoff /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[DIR]dist/a year ago -  
[   ]LICENSEa year ago 11K 
[TXT]README.mda year ago2.4K595aea1 more query options + view options [كارل مبارك]
[   ]package.jsona year ago1.3Kafd0ccc remove unused [كارل مبارك]
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