Socket
Book a DemoInstallSign in
Socket

then-retry

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

then-retry

Retry a function that returns a promise

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

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

FAQs

Package last updated on 04 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts