UNPKG

2.14 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/async-retry`
3
4# Summary
5This package contains type definitions for async-retry (https://github.com/vercel/async-retry).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-retry.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-retry/index.d.ts)
10````ts
11import { WrapOptions } from "retry";
12
13/**
14 * Retrying made simple, easy, and async.
15 *
16 * @example
17 * import retry = require('async-retry');
18 * import fetch from 'node-fetch';
19 *
20 * await retry(
21 * async (bail) => {
22 * // if anything throws, we retry
23 * const res = await fetch('https://google.com');
24 *
25 * if (403 === res.status) {
26 * // don't retry upon 403
27 * bail(new Error('Unauthorized'));
28 * return;
29 * }
30 *
31 * const data = await res.text();
32 * return data.substr(0, 500);
33 * },
34 * {
35 * retries: 5,
36 * }
37 * );
38 */
39declare function AsyncRetry<TRet>(fn: AsyncRetry.RetryFunction<TRet>, opts?: AsyncRetry.Options): Promise<TRet>;
40
41declare namespace AsyncRetry {
42 interface Options extends WrapOptions {
43 /**
44 * An optional function that is invoked after a new retry is performed. It's passed the
45 * `Error` that triggered it as a parameter.
46 */
47 onRetry?: ((e: Error, attempt: number) => any) | undefined;
48 }
49
50 /**
51 * @param bail A function you can invoke to abort the retrying (bail).
52 * @param attempt The attempt number. The absolute first attempt (before any retries) is `1`.
53 */
54 type RetryFunction<TRet> = (bail: (e: Error) => void, attempt: number) => TRet | Promise<TRet>;
55}
56
57export = AsyncRetry;
58
59````
60
61### Additional Details
62 * Last updated: Mon, 06 Nov 2023 22:41:04 GMT
63 * Dependencies: [@types/retry](https://npmjs.com/package/@types/retry)
64
65# Credits
66These definitions were written by [Albert Wu](https://github.com/albertywu), [Pablo Rodríguez](https://github.com/MeLlamoPablo), [Rafał Sawicki](https://github.com/rafsawicki), and [BendingBender](https://github.com/BendingBender).
67
\No newline at end of file