UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

25 lines 789 B
/** * @module Async */ import { TimeSpan } from "../../../utilities/_module-exports.js"; import { withJitter, } from "../../../async/backof-policies/_shared.js"; /** * Constant backoff policy with jitter * * IMPORT_PATH: `"@daiso-tech/core/async"` * @group BackoffPolicies */ export function constantBackoffPolicy(settings = {}) { return (_attempt, error) => { if (typeof settings === "function") { settings = settings(error); } let { delay = 1000 } = settings; if (delay instanceof TimeSpan) { delay = delay.toMilliseconds(); } const { jitter = 0.5, _mathRandom = Math.random } = settings; return withJitter(jitter, delay, _mathRandom); }; } //# sourceMappingURL=constant-backoff-policy.js.map