@creejs/commons-retrier
Version:
Common Utils About Task Retrying
147 lines (146 loc) • 5.74 kB
TypeScript
declare namespace _default {
export { retry };
export { always };
export { forever };
export { name };
export { infinite };
export { times };
export { maxRetries };
export { min };
export { max };
export { range };
export { fixedInterval };
export { fixedBackoff };
export { fixedIncrease };
export { linearBackoff };
export { factorIncrease };
export { exponentialBackoff };
export { shuttleInterval };
export { timeout };
export { taskTimeout };
export { start };
}
export default _default;
/**
*
* @param {Function} task
* @returns {Retrier}
*/
declare function retry(task: Function): Retrier;
/**
*
* @param {Function} task
* @returns {Retrier}
*/
declare function always(task: Function): Retrier;
/**
*
* @param {Function} task
* @returns {Retrier}
*/
declare function forever(task: Function): Retrier;
/**
* Creates a new Retrier instance with the specified name.
* @param {string} name - The name to assign to the retrier.
* @returns {Retrier} A new Retrier instance with the given name.
*/
export function name(name: string): Retrier;
/**
* Creates and returns a Retrier instance configured for infinite retries.
* @returns {Retrier} A Retrier instance with infinite retry behavior.
*/
export function infinite(): Retrier;
/**
* Creates a retrier configured to attempt an operation a specified number of times.
* @param {number} times - The maximum number of retry attempts.
* @returns {Retrier} A configured Retrier instance with the specified max retries.
*/
export function times(times: number): Retrier;
/**
* Alias for times.
* @param {number} maxRetries - The maximum number of retry attempts.
* @returns {Retrier} A configured Retrier instance with the specified max retries.
*/
export function maxRetries(maxRetries: number): Retrier;
/**
* Sets the minimum Interval for the retrier and returns the instance.
* @param {number} min - The minimum Interval in milliseconds.
* @returns {Retrier} The retrier instance with updated minimum Interval.
*/
export function min(min: number): Retrier;
/**
* Sets the maximum Interval for the retrier and returns the instance.
* @param {number} max - The maximum Interval in milliseconds.
* @returns {Retrier} The retrier instance with updated maximum Interval.
*/
export function max(max: number): Retrier;
/**
* Creates a retrier with the specified Interval range.
* @param {number} min - Minimum Interval.
* @param {number} max - Maximum Interval.
* @returns {Retrier} A new Retrier instance configured with specified Interval range.
*/
export function range(min: number, max: number): Retrier;
/**
* Creates a retrier with a fixed interval between attempts.
* @param {number} fixedInterval - The fixed interval in milliseconds between retry attempts.
* @returns {Retrier} A new Retrier instance configured with the specified fixed interval.
*/
export function fixedInterval(fixedInterval: number): Retrier;
/**
* Creates a retrier with a fixed backoff strategy.
* @param {number} fixedInterval - The fixed interval between retries in milliseconds.
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
* @returns {Retrier} A retrier instance configured with fixed backoff.
*/
export function fixedBackoff(fixedInterval: number, jitter?: number): Retrier;
/**
* Creates a retrier with a fixed increase strategy.
* @param {number} increasement - The fixed amount to increase on each retry.
* @returns {Retrier} A retrier instance configured with fixed increase.
*/
export function fixedIncrease(increasement: number): Retrier;
/**
* Creates a retrier with a fixed increase strategy.
* @param {number} increasement - The fixed amount to increase on each retry.
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
* @returns {Retrier} A retrier instance configured with fixed increase.
*/
export function linearBackoff(increasement: number, jitter?: number): Retrier;
/**
* Creates a new Retrier instance with factor-increase strategy.
* @param {number} factor - The factor by which to increase the interval on each retry.
* @returns {Retrier} A new Retrier instance with factor-increase strategy.
*/
export function factorIncrease(factor: number): Retrier;
/**
* Creates a new Retrier instance with exponential-backoff strategy.
* @param {number} [jitter=500]
* @returns {Retrier} A new Retrier instance
*/
export function exponentialBackoff(jitter?: number): Retrier;
/**
* Creates a Retrier instance with a shuttle-interval strategt.
* @param {number} stepLength - The interval step length of each change
* @returns {Retrier} A configured Retrier instance with shuttle-interval strategt.
*/
export function shuttleInterval(stepLength: number): Retrier;
/**
* Creates a Retrier instance with a total-opertion timeout.
* @param {number} timeout - The timeout value in milliseconds.
* @returns {Retrier} A Retrier instance configured with the given timeout.
*/
export function timeout(timeout: number): Retrier;
/**
* Creates a retrier instance with a single-task timeout.
* @param {number} timeout - The timeout duration in milliseconds for the retrier task.
* @returns {Retrier} A Retrier instance configured with the given task timeout.
*/
export function taskTimeout(timeout: number): Retrier;
/**
* Creates a new Retrier instance, sets the task to be retried, and starts the retry process.
* @param {Function} task - The asynchronous task function to be retried.
* @returns {Promise<*>} A promise that resolves when the retry process completes.
*/
export function start(task: Function): Promise<any>;
import Retrier from './retrier.js';