UNPKG

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

24 lines (23 loc) 986 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.waitUntilAsyncDecorator = waitUntilAsyncDecorator; exports.waitUntilDecorator = waitUntilDecorator; const wait_1 = require("./wait"); function waitUntilAsyncDecorator(fn, duration, error) { return (...args) => { const wrappedFn = () => fn(...args); return (0, wait_1.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? */ function waitUntilDecorator(fn, duration, error) { return (...args) => { const wrappedFn = () => fn(...args); return (0, wait_1.waitUntil)(wrappedFn, duration, error); }; }