@types/retry
- Version 0.12.5
- Published
- 7.57 kB
- No dependencies
- MIT license
Install
npm i @types/retry
yarn add @types/retry
pnpm add @types/retry
Overview
TypeScript definitions for retry
Index
Functions
Interfaces
Type Aliases
Functions
function createTimeout
createTimeout: (attempt: number, options?: CreateTimeoutOptions) => number;
Create a new timeout (in milliseconds) based on the given parameters.
Parameter attempt
Representing for which retry the timeout should be calculated. timeout
function operation
operation: (options?: OperationOptions) => RetryOperation;
Create a new RetryOperation object.
Parameter
[options.retries=10] The maximum amount of times to retry the operation.
Parameter
[options.factor=2] The exponential factor to use.
Parameter
[options.minTimeout=1000] The number of milliseconds before starting the first retry.
Parameter
[options.maxTimeout=Infinity] The maximum number of milliseconds between two retries.
Parameter
[options.randomize=false] Randomizes the timeouts by multiplying a factor between 1-2.
Parameter
[options.forever=false] Wether to retry forever.
Parameter
[options.unref=false] Wether to unref the setTimeout's.
function timeouts
timeouts: (options?: TimeoutsOptions) => number[];
Get an array with timeouts and their return values in milliseconds.
function wrap
wrap: { (object: object, methods?: string[]): void; (object: object, options?: WrapOptions, methods?: string[]): void;};
Wrap all functions of the object with retry.
Parameter object
The object to be wrapped
Parameter methods
Methods which need to be wrapped
Interfaces
interface AttemptTimeoutOptions
interface AttemptTimeoutOptions {}
interface CreateTimeoutOptions
interface CreateTimeoutOptions {}
property factor
factor?: number | undefined;
The exponential factor to use. 2
property maxTimeout
maxTimeout?: number | undefined;
The maximum number of milliseconds between two retries. Infinity
property minTimeout
minTimeout?: number | undefined;
The number of milliseconds before starting the first retry. 1000
property randomize
randomize?: boolean | undefined;
Randomizes the timeouts by multiplying a factor between 1-2. false
interface RetryOperation
interface RetryOperation {}
method attempt
attempt: ( fn: (currentAttempt: number) => void, timeoutOps?: AttemptTimeoutOptions) => void;
Defines the function that is to be retried and executes it for the first time right away.
Parameter fn
The function that is to be retried.
currentAttempt
represents the number of attempts callback has been executed so far.Parameter
[timeoutOps.timeout] A timeout in milliseconds.
Parameter
[timeoutOps.callback] Callback to execute when the operation takes longer than the timeout.
method attempts
attempts: () => number;
Returns an int representing the number of attempts it took to call
fn
before it was successful.
method errors
errors: () => Error[];
Returns an array of all errors that have been passed to
retryOperation.retry()
so far. The returning array has the errors ordered chronologically based on when they were passed toretryOperation.retry()
, which means the first passed error is at index zero and the last is at the last index.
method mainError
mainError: () => Error | null;
A reference to the error object that occured most frequently. Errors are compared using the
error.message
property. If multiple error messages occured the same amount of time, the last error object with that message is returned.If no errors occured so far the value will be
null
.
method reset
reset: () => void;
Resets the internal state of the operation object, so that you can call
attempt()
again as if this was a new operation object.
method retry
retry: (err?: Error) => boolean;
Returns
false
when noerror
value is given, or the maximum amount of retries has been reached. Otherwise it returnstrue
, and retries the operation after the timeout for the current attempt number.
method stop
stop: () => void;
Stops the operation being retried. Useful for aborting the operation on a fatal error etc.
interface TimeoutsOptions
interface TimeoutsOptions extends CreateTimeoutOptions {}
property retries
retries?: number | undefined;
The maximum amount of times to retry the operation. 10
interface WrapOptions
interface WrapOptions extends TimeoutsOptions {}
property forever
forever?: boolean | undefined;
Whether to retry forever. false
property maxRetryTime
maxRetryTime?: number | undefined;
The maximum time (in milliseconds) that the retried operation is allowed to run. Infinity
property unref
unref?: boolean | undefined;
Whether to [unref](https://nodejs.org/api/timers.html#timers_unref) the setTimeout's. false
Type Aliases
type OperationOptions
type OperationOptions = WrapOptions | number[];
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/retry
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/retry)
- HTML<a href="https://www.jsdocs.io/package/@types/retry"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2704 ms. - Missing or incorrect documentation? Open an issue for this package.