JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1018535
  • Score
    100M100P100Q187663F
  • License MIT

TypeScript definitions for async-retry

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@types/async-retry) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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

    // Type definitions for async-retry 1.4
    // Project: https://github.com/vercel/async-retry
    // Definitions by: Albert Wu <https://github.com/albertywu>
    //                 Pablo Rodríguez <https://github.com/MeLlamoPablo>
    //                 Rafał Sawicki <https://github.com/rafsawicki>
    //                 BendingBender <https://github.com/BendingBender>
    // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
    
    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>(fn: AsyncRetry.RetryFunction<TRet>, opts?: AsyncRetry.Options): Promise<TRet>;
    
    declare namespace AsyncRetry {
        interface Options extends WrapOptions {
            /**
             * 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: Error, attempt: number) => any) | 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> = (bail: (e: Error) => void, attempt: number) => TRet | Promise<TRet>;
    }
    
    export = AsyncRetry;
    

    Additional Details

    • Last updated: Fri, 19 Aug 2022 20:02:26 GMT
    • Dependencies: @types/retry
    • Global values: none

    Credits

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