Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/async-retry

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/async-retry

TypeScript definitions for async-retry

  • 1.4.9
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Installation

npm install --save @types/async-retry

Summary

This package contains type definitions for async-retry (https://github.com/vercel/async-retry).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-retry.

index.d.ts

import { WrapOptions } from "retry";

/**
 * Retrying made simple, easy, and async.
 *
 * @example
 * import retry = require('async-retry');
 * import fetch from 'node-fetch';
 *
 * await retry(
 *   async (bail) => {
 *     // if anything throws, we retry
 *     const res = await fetch('https://google.com');
 *
 *     if (403 === res.status) {
 *       // don't retry upon 403
 *       bail(new Error('Unauthorized'));
 *       return;
 *     }
 *
 *     const data = await res.text();
 *     return data.substr(0, 500);
 *   },
 *   {
 *     retries: 5,
 *   }
 * );
 */
declare function AsyncRetry<TRet, TErr = unknown>(
    fn: AsyncRetry.RetryFunction<TRet, TErr>,
    opts?: AsyncRetry.Options<TErr> | number[],
): Promise<TRet>;

declare namespace AsyncRetry {
    interface Options<TErr = unknown> extends Omit<WrapOptions, "randomize"> {
        /**
         * An optional function that is invoked after a new retry is performed. It's passed the
         * `Error` that triggered it as a parameter.
         */
        onRetry?: ((e: TErr, attempt: number) => any) | undefined;
        /**
         * Randomizes the timeouts by multiplying a factor between 1-2.
         * @default true
         */
        randomize?: boolean | undefined;
    }

    /**
     * @param bail A function you can invoke to abort the retrying (bail).
     * @param attempt The attempt number. The absolute first attempt (before any retries) is `1`.
     */
    type RetryFunction<TRet, TErr = unknown> = (bail: (e: TErr) => void, attempt: number) => TRet | Promise<TRet>;
}

export = AsyncRetry;

Additional Details

  • Last updated: Wed, 02 Oct 2024 18:10:02 GMT
  • Dependencies: @types/retry

Credits

These definitions were written by Albert Wu, Pablo Rodríguez, Rafał Sawicki, and BendingBender.

FAQs

Package last updated on 02 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc