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

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