ts-retry
Version:
A little retry tool to execute a function until the function is successful. Can also bind a timeout to a function. This lib is usable in typescript, in javascript, in node, in SPA tools (rest, Vue, Svelte...) and browser (available in ESM and common js fo
15 lines (14 loc) • 650 B
JavaScript
import { defaultDelay, defaultMaxTry, getDefaultRetryOptions } from "./options";
export function getRetryParameters(currentTry, retryOptions) {
const fullOptions = Object.assign(Object.assign({}, getDefaultRetryOptions()), retryOptions);
return Object.assign(Object.assign({}, fullOptions), { currentTry, maxTry: fullOptions.maxTry || defaultMaxTry, delay: getDelay(fullOptions.delay), until: fullOptions.until ? fullOptions.until : () => true });
}
function getDelay(delay) {
if (delay === undefined) {
return () => defaultDelay;
}
if (typeof delay === 'function') {
return delay;
}
return () => delay;
}