aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/exponential-backoff/src/delay
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/exponential-backoff/src/delay')
-rw-r--r--node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts65
-rw-r--r--node_modules/exponential-backoff/src/delay/always/always.delay.ts3
-rw-r--r--node_modules/exponential-backoff/src/delay/delay.base.ts34
-rw-r--r--node_modules/exponential-backoff/src/delay/delay.factory.ts18
-rw-r--r--node_modules/exponential-backoff/src/delay/delay.interface.ts4
-rw-r--r--node_modules/exponential-backoff/src/delay/skip-first/skip-first.delay.ts15
6 files changed, 0 insertions, 139 deletions
diff --git a/node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts b/node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts
deleted file mode 100644
index 8a08cd8..0000000
--- a/node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import { AlwaysDelay } from "./always.delay";
-import { IBackOffOptions, getSanitizedOptions } from "../../options";
-
-describe(AlwaysDelay.name, () => {
- let options: IBackOffOptions;
- let delay: AlwaysDelay;
-
- function initClass() {
- delay = new AlwaysDelay(options);
- }
-
- beforeEach(() => {
- options = getSanitizedOptions({});
- initClass();
- jest.useFakeTimers();
- });
-
- it(`when calling #apply, the delay is equal to the starting delay`, async () => {
- const spy = jest.fn();
- delay.apply().then(spy);
- jest.runTimersToTime(options.startingDelay);
- await Promise.resolve();
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- it(`when the attempt number is 1, when calling #apply,
- the delay is equal to the starting delay multiplied by the time multiple`, async () => {
- delay.setAttemptNumber(1);
-
- const spy = jest.fn();
- delay.apply().then(spy);
- jest.runTimersToTime(options.startingDelay * options.timeMultiple);
- await Promise.resolve();
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- it(`when the attempt number is 2, when calling #apply,
- the delay is equal to the starting delay multiplied by the time multiple raised by the attempt number`, async () => {
- const attemptNumber = 2;
- delay.setAttemptNumber(attemptNumber);
-
- const spy = jest.fn();
- delay.apply().then(spy);
- jest.runTimersToTime(
- options.startingDelay * Math.pow(options.timeMultiple, attemptNumber)
- );
- await Promise.resolve();
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-
- it(`when the #maxDelay is less than #startingDelay, when calling #apply,
- the delay is equal to the #maxDelay`, async () => {
- options.maxDelay = options.startingDelay - 1;
-
- const spy = jest.fn();
- delay.apply().then(spy);
- jest.runTimersToTime(options.maxDelay);
- await Promise.resolve();
-
- expect(spy).toHaveBeenCalledTimes(1);
- });
-});
diff --git a/node_modules/exponential-backoff/src/delay/always/always.delay.ts b/node_modules/exponential-backoff/src/delay/always/always.delay.ts
deleted file mode 100644
index ec86c62..0000000
--- a/node_modules/exponential-backoff/src/delay/always/always.delay.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import { Delay } from "../delay.base";
-
-export class AlwaysDelay extends Delay {} \ No newline at end of file
diff --git a/node_modules/exponential-backoff/src/delay/delay.base.ts b/node_modules/exponential-backoff/src/delay/delay.base.ts
deleted file mode 100644
index bed90d6..0000000
--- a/node_modules/exponential-backoff/src/delay/delay.base.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { IDelay } from "./delay.interface";
-import { IBackOffOptions } from "../options";
-import { JitterFactory } from "../jitter/jitter.factory";
-
-export abstract class Delay implements IDelay {
- protected attempt = 0;
- constructor(private options: IBackOffOptions) {}
-
- public apply() {
- return new Promise(resolve => setTimeout(resolve, this.jitteredDelay));
- }
-
- public setAttemptNumber(attempt: number) {
- this.attempt = attempt;
- }
-
- private get jitteredDelay() {
- const jitter = JitterFactory(this.options);
- return jitter(this.delay);
- }
-
- private get delay() {
- const constant = this.options.startingDelay;
- const base = this.options.timeMultiple;
- const power = this.numOfDelayedAttempts;
- const delay = constant * Math.pow(base, power);
-
- return Math.min(delay, this.options.maxDelay);
- }
-
- protected get numOfDelayedAttempts() {
- return this.attempt;
- }
-}
diff --git a/node_modules/exponential-backoff/src/delay/delay.factory.ts b/node_modules/exponential-backoff/src/delay/delay.factory.ts
deleted file mode 100644
index 95e89fb..0000000
--- a/node_modules/exponential-backoff/src/delay/delay.factory.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { IBackOffOptions } from "../options";
-import { SkipFirstDelay } from "./skip-first/skip-first.delay";
-import { AlwaysDelay } from "./always/always.delay";
-import { IDelay } from "./delay.interface";
-
-export function DelayFactory(options: IBackOffOptions, attempt: number): IDelay {
- const delay = initDelayClass(options);
- delay.setAttemptNumber(attempt);
- return delay;
-}
-
-function initDelayClass(options: IBackOffOptions) {
- if (!options.delayFirstAttempt) {
- return new SkipFirstDelay(options);
- }
-
- return new AlwaysDelay(options);
-} \ No newline at end of file
diff --git a/node_modules/exponential-backoff/src/delay/delay.interface.ts b/node_modules/exponential-backoff/src/delay/delay.interface.ts
deleted file mode 100644
index 6ecc8da..0000000
--- a/node_modules/exponential-backoff/src/delay/delay.interface.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export interface IDelay {
- apply: () => Promise<unknown>;
- setAttemptNumber: (attempt: number) => void;
-}
diff --git a/node_modules/exponential-backoff/src/delay/skip-first/skip-first.delay.ts b/node_modules/exponential-backoff/src/delay/skip-first/skip-first.delay.ts
deleted file mode 100644
index 9f2b7f5..0000000
--- a/node_modules/exponential-backoff/src/delay/skip-first/skip-first.delay.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { Delay } from "../delay.base";
-
-export class SkipFirstDelay extends Delay {
- public async apply() {
- return this.isFirstAttempt ? true : super.apply();
- }
-
- private get isFirstAttempt() {
- return this.attempt === 0;
- }
-
- protected get numOfDelayedAttempts() {
- return this.attempt - 1;
- }
-} \ No newline at end of file