UNPKG

@augmentcode/ag-redux-toolkit

Version:

Redux + Saga state management for Svelte apps — designed for AI agents. Includes runtime TypeScript source, AI skills, and reference documentation for robust, observable, high-performance state management.

26 lines (25 loc) • 870 B
import { call, delay, race } from "typed-redux-saga"; //#region src/utils/sagas/retry-with-timeout.ts function* retryWithTimeout(fn, options) { const { maxRetries: rawMaxRetries, timeoutMs, getDelayMs = (attempt) => 1e3 * (attempt + 1), onAttemptError } = options; const maxRetries = Math.max(0, rawMaxRetries); const totalAttempts = maxRetries + 1; return (yield* race({ outcome: call(function* () { for (let attempt = 0; attempt < totalAttempts; attempt++) try { yield* call(fn); return "success"; } catch (error) { try { onAttemptError?.(error, attempt, totalAttempts); } catch {} if (attempt < maxRetries) yield* delay(getDelayMs(attempt)); } return "retries-exhausted"; }), timeout: delay(timeoutMs) })).outcome ?? "timeout"; } //#endregion export { retryWithTimeout }; //# sourceMappingURL=retry-with-timeout.js.map