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

1.0.1 • Public • Published

then-retry

Retry functions that return promises

Rolling Versions

Installation

yarn add then-retry

Usage

import retry, { withRetry } from "then-retry";

// to retry a one of operation
await retry(() => someAsyncOp("hello world"));

// to retry every call of a given function
const someRetriedOp = withRetry(someAsyncOp);
await someRetriedOp("hello world");

The following options can be passed as a second arg to either retry or withRetry:

  • shouldRetry(err: unknown, failedAttemptCount: number) => boolean - return true if you would like to try again. err is the most recent error. failedAttemptCount is the number of failed attempts (so the first time this is called, it is 1). The default implementation returns true for the first 10 attempts.
  • retryDelay(err: unknown, failedAttemptCount: number) => number (milliseconds) - return the number of milliseconds to wait before trying again. The default implementation returns 0 for the first few attempts, and then performs a randomized exponential backoff starting at 100ms.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i then-retry

Weekly Downloads

98

Version

1.0.1

License

MIT

Unpacked Size

6.85 kB

Total Files

6

Last publish

Collaborators

  • forbeslindesay