From 7d40a40ea9f85e081aa4ec60e9310502c2109023 Mon Sep 17 00:00:00 2001 From: Harvmaster Date: Sat, 18 Jul 2026 13:56:43 +0000 Subject: [PATCH] use js private --- source/exponential-backoff.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/exponential-backoff.ts b/source/exponential-backoff.ts index 47259bc..94ff838 100644 --- a/source/exponential-backoff.ts +++ b/source/exponential-backoff.ts @@ -10,7 +10,7 @@ import { ExponentialBackoffStoppedRetriesError, ExponentialBackoffMaxRetriesHitE * The growth rate is the factor by which the delay increases with each attempt. */ export class ExponentialBackoff { - private readonly options: ExponentialBackoffOptions; + readonly #options: ExponentialBackoffOptions; /** * Creates a new exponential-backoff instance. @@ -25,7 +25,7 @@ export class ExponentialBackoff { * @param options.jitter - Maximum proportional reduction subtracted from each delay (0–1). Default: `0.1`. */ constructor(options: Partial = {}) { - this.options = { + this.#options = { maxDelay: 10_000, maxAttempts: 10, baseDelay: 1_000, @@ -125,7 +125,7 @@ export class ExponentialBackoff { let attempt = 0; // If the max attempts is 0, we should continue indefinitely. - const unlimitedAttempts = this.options.maxAttempts === 0; + const unlimitedAttempts = this.#options.maxAttempts === 0; // Loop until we succeed, hit the max attempts, or the abort signal is activated while (true) { @@ -146,7 +146,7 @@ export class ExponentialBackoff { // Calculate the count for next attempt. Do this now so we can exit before waiting and before running the next attempt. const nextAttemptCount = attempt + 1; - const nextAttemptExceedsMaxAttempts = nextAttemptCount >= this.options.maxAttempts; + const nextAttemptExceedsMaxAttempts = nextAttemptCount >= this.#options.maxAttempts; // If the next attempt exceeds the max attempts, break out of the loop if (!unlimitedAttempts && nextAttemptExceedsMaxAttempts) { @@ -160,7 +160,7 @@ export class ExponentialBackoff { } // Wait before going to the next attempt - const delay = ExponentialBackoff.calculateDelay(this.options, attempt); + const delay = ExponentialBackoff.calculateDelay(this.#options, attempt); await new Promise((resolve) => setTimeout(resolve, delay)); attempt++;