Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import type { RedisReconnectStrategy } from "../options/options.js";
/**
* Compute the next backoff delay in milliseconds for the configured
* exponential reconnect strategy. Capped at `maxDelayMs`. Pure function,
* trivially deterministic — the broker drives an external timer.
*/
export function nextReconnectDelayMs(
attempt: number,
strategy: RedisReconnectStrategy
): number {
if (attempt < 0) return strategy.initialDelayMs;
const raw = strategy.initialDelayMs * strategy.multiplier ** attempt;
return Math.min(raw, strategy.maxDelayMs);
}
/**
* Decide whether the reconnect loop should give up. Once `attempt` reaches
* the configured maximum, the broker raises `WS_BROKER_REDIS.RECONNECT_FAILED`
* and surfaces `down` health.
*/
export function shouldGiveUp(
attempt: number,
strategy: RedisReconnectStrategy
): boolean {
return attempt >= strategy.maxAttempts;
}