/** * Reconnection loop with exponential backoff. * * Calls `connectFn` in a while loop. On normal resolve (connection closed), * the backoff resets. On thrown error (connection failed), the current delay is * used, then doubled for the next retry. * The loop exits when `abortSignal` fires.
*/
export async function runWithReconnect(
connectFn: () => Promise<void>,
opts: RunWithReconnectOpts = {},
): Promise<void> { const { initialDelayMs = 2000, maxDelayMs = 60_000 } = opts; const jitterRatio = Math.max(0, opts.jitterRatio ?? 0); const random = opts.random ?? Math.random;
let retryDelay = initialDelayMs;
let attempt = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.