@types/async-retry
TypeScript icon, indicating that this package has built-in type declarations

1.4.9 • Public • Published

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.

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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.4.8575,766ts4.7
1.4.8575,766ts4.6
1.4.8575,766ts4.5
1.4.5177,054ts4.0
1.4.5177,054ts4.4
1.4.5177,054ts4.3
1.4.5177,054ts4.2
1.4.5177,054ts4.1
1.4.9120,432ts5.6
1.4.9120,432ts5.7
1.4.9120,432latest
1.4.9120,432ts4.8
1.4.9120,432ts4.9
1.4.9120,432ts5.1
1.4.9120,432ts5.0
1.4.9120,432ts5.2
1.4.9120,432ts5.3
1.4.9120,432ts5.4
1.4.9120,432ts5.5
1.4.9120,432ts5.8
1.4.3101,572ts3.7
1.4.3101,572ts3.6
1.4.3101,572ts3.8
1.4.124,009ts2.4
1.4.124,009ts2.9
1.4.124,009ts2.8
1.4.124,009ts2.7
1.4.124,009ts2.6
1.4.124,009ts2.5
1.4.124,009ts2.3
1.4.421,598ts3.9
1.4.216,762ts3.0
1.4.216,762ts3.4
1.4.216,762ts3.5
1.4.216,762ts3.2
1.4.216,762ts3.1
1.4.216,762ts3.3
1.3.01,748ts2.1
1.3.01,748ts2.0
1.3.01,748ts2.2

Version History

VersionDownloads (Last 7 Days)Published
1.4.9120,432
1.4.8575,766
1.4.715,732
1.4.64,865
1.4.5177,054
1.4.421,598
1.4.3101,572
1.4.216,762
1.4.124,009
1.4.010
1.3.01,748
1.2.1439,274
1.2.032
1.1.08

Package Sidebar

Install

npm i @types/async-retry

Weekly Downloads

1,498,862

Version

1.4.9

License

MIT

Unpacked Size

6.43 kB

Total Files

5

Last publish

Collaborators

  • types