@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.
31 lines • 1.03 kB
JavaScript
/**
* @module Async
*/
import { callInvokable, isInvokable, 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 (isInvokable(settings)) {
const dynamicSettings = callInvokable(settings, error);
if (dynamicSettings === undefined) {
settings = {};
}
else {
settings = dynamicSettings;
}
}
let { delay = 1000 } = settings;
if (delay instanceof TimeSpan) {
delay = delay.toMilliseconds();
}
const { jitter = 0.5, _mathRandom = Math.random } = settings;
return TimeSpan.fromMilliseconds(withJitter(jitter, delay, _mathRandom));
};
}
//# sourceMappingURL=constant-backoff-policy.js.map