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
20 lines (19 loc) • 809 B
JavaScript
import { waitUntil, waitUntilAsync } from "./wait";
export function waitUntilAsyncDecorator(fn, duration, error) {
return (...args) => {
const wrappedFn = () => fn(...args);
return waitUntilAsync(wrappedFn, duration, error);
};
}
/** a waitUntil decorator
* @param fn the function to execute
* @param duration timeout in milliseconds
* @param [error] custom error to throw when fn duration exceeded duration. If not provided a TimeoutError is thrown.
* @returns: a function hat takes same parameters as fn. It calls fn using waitUntil and returns/throws the results/error of this call?
*/
export function waitUntilDecorator(fn, duration, error) {
return (...args) => {
const wrappedFn = () => fn(...args);
return waitUntil(wrappedFn, duration, error);
};
}