@creejs/commons-retrier
Version:
Common Utils About Task Retrying
63 lines (61 loc) • 2.2 kB
TypeScript
export default class Policy {
_min: number;
_max: number;
_nextInterval: number;
_jitter: number;
set jitter(jitter: number);
get jitter(): number;
/**
* Copies settings to target policy.
* 1. range
* 2. nextInterval value
* @param {Policy} targetPolicy - The policy to modify.
*/
copyPolicySettingTo(targetPolicy: Policy): void;
/**
* Sets a fixed interval retry policy.
}
/**
* Sets the minimum and maximum intervals for retries.
* @param {number} min - Minimum delay in milliseconds (must be positive and less than max)
* @param {number} max - Maximum delay in milliseconds (must be positive and greater than min)
* @returns {this} Returns the Retrier instance for chaining
* @throws {Error} If min is not less than max or if values are not positive
*/
range(min: number, max: number): this;
/**
* Sets the minimum retry delay in milliseconds.
* 1. will change currentInterval to min
* @param {number} min - The minimum delay (must be positive and less than max).
* @returns {this} The retrier instance for chaining.
* @throws {Error} If min is not positive or is greater than/equal to max.
*/
min(min: number): this;
/**
* Sets the maximum retry retry delay in milliseconds.
* @param {number} max - The maximum delay (must be positive and greater than min).
* @throws {Error} If max is not greater than min.
* @returns {this} The retrier instance for chaining.
*/
max(max: number): this;
reset(): this;
/**
* Interval ms of next execution
* @param {number} retries current retry times
* @returns {number}
*/
generate(retries: number): number;
/**
* @param {number} retries current retry times
* @returns {number}
*/
_increase(retries: number): number;
/**
* subclass should implement this method
* @param {number} retries current retry times
* @returns {number} The interval in milliseconds to wait before the next retry attempt.
* @protected
*/
protected _next(retries: number): number;
}
export { Policy as PolicyType };