@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
25 lines (24 loc) • 723 B
TypeScript
/**
* Calls `callback` until it doesn't throw an error or throws an error when `maxRetries` is reached.
* Similar to the `waitUntil` guard from '@augment-vir/assert' but doesn't check the callback's
* output.
*
* @category Function
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {callWithRetries} from '@augment-vir/common';
*
* const result = callWithRetries(5, () => {
* if (Math.random() < 0.5) {
* return 'done';
* } else {
* throw new Error();
* }
* });
* ```
*
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export declare function callWithRetries<const T>(maxRetries: number, callback: () => T): T;