mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
retry: Fix lint (#20915)
This commit is contained in:
Vendored
+81
-46
@@ -8,12 +8,11 @@ export interface RetryOperation {
|
||||
/**
|
||||
* Defines the function that is to be retried and executes it for the first time right away.
|
||||
*
|
||||
* @param {function} callback The function that is to be retried
|
||||
* @param {number} callback.current Number of attempts callback has been executed so far.
|
||||
* @param {number} [options.timeout] A timeout in milliseconds.
|
||||
* @param {function} [options.callback] Callback to execute when the operation takes longer than the timeout.
|
||||
* @param callback The function that is to be retried
|
||||
* @param callback.current Number of attempts callback has been executed so far.
|
||||
* @param [options.timeout] A timeout in milliseconds.
|
||||
* @param [options.callback] Callback to execute when the operation takes longer than the timeout.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
attempt(callback: (current: number) => void, options?: AttemptOptions): void;
|
||||
|
||||
@@ -21,16 +20,13 @@ export interface RetryOperation {
|
||||
* Returns false when no error value is given, or the maximum amount of retries has been reached.
|
||||
* Otherwise it returns true, and retries the operation after the timeout for the current attempt number.
|
||||
*
|
||||
* @param {Error} [err]
|
||||
*
|
||||
* @return {boolean}
|
||||
*/
|
||||
retry(err?: Error): boolean;
|
||||
|
||||
/**
|
||||
* The number of attempts it took to call the retrying function before it was successful.
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
attempts(): number;
|
||||
|
||||
@@ -38,14 +34,13 @@ export interface RetryOperation {
|
||||
* A reference to the error object that occured most frequently.
|
||||
* Errors are compared using the error.message property.
|
||||
*
|
||||
* @return {(Error|null)} If no errors occured so far the value will be null.
|
||||
* @return If no errors occured so far the value will be null.
|
||||
*/
|
||||
mainError(): Error | null;
|
||||
|
||||
/**
|
||||
* Returns an array of all errors that have been passed to RetryOperation.retry() so far.
|
||||
*
|
||||
* @return {Error[]}
|
||||
*/
|
||||
errors(): Error[];
|
||||
|
||||
@@ -63,39 +58,48 @@ export interface AttemptOptions {
|
||||
/**
|
||||
* Create a new RetryOperation object.
|
||||
*
|
||||
* @param {number} [options.retries=10] The maximum amount of times to retry the operation.
|
||||
* @param {number} [options.factor=2] The exponential factor to use.
|
||||
* @param {number} [options.minTimeout=1000] The number of milliseconds before starting the first retry.
|
||||
* @param {number} [options.maxTimeout=Infinity] The maximum number of milliseconds between two retries.
|
||||
* @param {boolean} [options.randomize=false] Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
* @param {boolean} [options.forever=false] Wether to retry forever.
|
||||
* @param {boolean} [options.unref=false] Wether to unref the setTimeout's.
|
||||
* @param [options.retries=10] The maximum amount of times to retry the operation.
|
||||
* @param [options.factor=2] The exponential factor to use.
|
||||
* @param [options.minTimeout=1000] The number of milliseconds before starting the first retry.
|
||||
* @param [options.maxTimeout=Infinity] The maximum number of milliseconds between two retries.
|
||||
* @param [options.randomize=false] Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
* @param [options.forever=false] Wether to retry forever.
|
||||
* @param [options.unref=false] Wether to unref the setTimeout's.
|
||||
*
|
||||
* @return {RetryOperation}
|
||||
*/
|
||||
export function operation(options?: OperationOptions): RetryOperation;
|
||||
|
||||
export interface OperationOptions {
|
||||
/**
|
||||
* The maximum amount of times to retry the operation.
|
||||
* @default 10
|
||||
*/
|
||||
retries?: number;
|
||||
/**
|
||||
* The exponential factor to use.
|
||||
* @default 2
|
||||
*/
|
||||
factor?: number;
|
||||
/**
|
||||
* The number of milliseconds before starting the first retry.
|
||||
* @default 1000
|
||||
*/
|
||||
minTimeout?: number;
|
||||
/**
|
||||
* The maximum number of milliseconds between two retries.
|
||||
* @default Infinity
|
||||
*/
|
||||
maxTimeout?: number;
|
||||
/**
|
||||
* Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
* @default false
|
||||
*/
|
||||
randomize?: boolean;
|
||||
forever?: boolean;
|
||||
unref?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array with timeouts and their return values in milliseconds.
|
||||
*
|
||||
* @param {number} [options.retries=10] The maximum amount of times to retry the operation.
|
||||
* @param {number} [options.factor=2] The exponential factor to use.
|
||||
* @param {number} [options.minTimeout=1000] The number of milliseconds before starting the first retry.
|
||||
* @param {number} [options.maxTimeout=Infinity] The maximum number of milliseconds between two retries.
|
||||
* @param {boolean} [options.randomize=false] Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
*
|
||||
* @return {number[]}
|
||||
*/
|
||||
/** Get an array with timeouts and their return values in milliseconds. */
|
||||
export function timeouts(options?: TimeoutsOptions): number[];
|
||||
|
||||
export interface TimeoutsOptions {
|
||||
@@ -109,46 +113,77 @@ export interface TimeoutsOptions {
|
||||
/**
|
||||
* Create a new timeout (in milliseconds) based on the given parameters.
|
||||
*
|
||||
* @param {number} attempt Representing for which retry the timeout should be calculated.
|
||||
* @param {number} [options.factor=2] The exponential factor to use.
|
||||
* @param {number} [options.minTimeout=1000] The number of milliseconds before starting the first retry.
|
||||
* @param {number} [options.maxTimeout=Infinity] The maximum number of milliseconds between two retries.
|
||||
* @param {boolean} [options.randomize=false] Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
*
|
||||
* @return {number} timeout
|
||||
* @param attempt Representing for which retry the timeout should be calculated.
|
||||
* @return timeout
|
||||
*/
|
||||
export function createTimeout(attempt: number, options?: CreateTimeoutOptions): number;
|
||||
|
||||
export interface CreateTimeoutOptions {
|
||||
/**
|
||||
* The exponential factor to use.
|
||||
* @default 2
|
||||
*/
|
||||
factor?: number;
|
||||
/**
|
||||
* The number of milliseconds before starting the first retry.
|
||||
* @default 1000
|
||||
*/
|
||||
minTimeout?: number;
|
||||
/**
|
||||
* The maximum number of milliseconds between two retries.
|
||||
* @default Infinity
|
||||
*/
|
||||
maxTimeout?: number;
|
||||
/**
|
||||
* Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
* @default false
|
||||
*/
|
||||
randomize?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap all functions of the object with retry.
|
||||
*
|
||||
* @param {object} object The object to be wrapped
|
||||
* @param {number} [options.retries=10] The maximum amount of times to retry the operation.
|
||||
* @param {number} [options.factor=2] The exponential factor to use.
|
||||
* @param {number} [options.minTimeout=1000] The number of milliseconds before starting the first retry.
|
||||
* @param {number} [options.maxTimeout=Infinity] The maximum number of milliseconds between two retries.
|
||||
* @param {boolean} [options.randomize=false] Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
* @param {boolean} [options.forever=false] Wether to retry forever.
|
||||
* @param {boolean} [options.unref=false] Wether to unref the setTimeout's.
|
||||
* @param {string[]} [methods] Methods which need to be wrapped
|
||||
* @param object The object to be wrapped
|
||||
* @param methods Methods which need to be wrapped
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
export function wrap(object: object, options?: WrapOptions, methods?: string[]): void;
|
||||
|
||||
export interface WrapOptions {
|
||||
/**
|
||||
* The maximum amount of times to retry the operation.
|
||||
* @default 10
|
||||
*/
|
||||
retries?: number;
|
||||
/**
|
||||
* The exponential factor to use.
|
||||
* @default 2
|
||||
*/
|
||||
factor?: number;
|
||||
/**
|
||||
* The number of milliseconds before starting the first retry.
|
||||
* @default 1000
|
||||
*/
|
||||
minTimeout?: number;
|
||||
/**
|
||||
* The maximum number of milliseconds between two retries.
|
||||
* @default Infinity
|
||||
*/
|
||||
maxTimeout?: number;
|
||||
/**
|
||||
* Randomizes the timeouts by multiplying a factor between 1-2.
|
||||
* @default false
|
||||
*/
|
||||
randomize?: boolean;
|
||||
/**
|
||||
* Whether to retry forever.
|
||||
* @default false
|
||||
*/
|
||||
forever?: boolean;
|
||||
/**
|
||||
* Whether to unref the setTimeout's.
|
||||
* @default false
|
||||
*/
|
||||
unref?: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user