backo2: expose properties, improve docs (#38451)

This commit is contained in:
r1b 2019-09-18 13:07:06 -04:00 committed by Daniel Rosenwasser
parent acb3cb292b
commit 028523c9cb
2 changed files with 31 additions and 3 deletions

View File

@ -10,4 +10,9 @@ const backoff3 = new Backoff({
});
const y: number = backoff3.duration();
const attempts: number = backoff3.attempts;
const min: number = backoff3.ms;
const max: number = backoff3.max;
const jitter: number = backoff3.jitter;
const factor: number = backoff3.factor;
backoff3.reset();

View File

@ -14,17 +14,40 @@ type BackoffOptions = Partial<{
declare class Backoff {
constructor(opts?: BackoffOptions);
/**
* The number of previous attempts
*/
attempts: number;
/**
* A lower bound on the duration between attempts
*/
ms: number;
/**
* An upper bound on the duration between attempts
*/
max: number;
/**
* An upper bound on the variance around the duration between attempts
*/
jitter: number;
/**
* The base to which the attempt is raised as an exponent
*/
factor: number;
/**
* Compute the backoff duration and increment the number of attempts
*/
duration(): number;
/**
* Reset the number of attempts.
* Reset the number of attempts
*/
reset(): void;
/**
* Set the minimum duration
* Set the minimum duration between attempts
*/
setMin(min: number): void;
/**
* Set the maximum duration
* Set the maximum duration between attempts
*/
setMax(max: number): void;
/**