rx-retry
Version:
Package for retries in RxJS, Promises and NestJS
28 lines (27 loc) • 1.18 kB
TypeScript
import type { ResolveRetryConfig } from '../models';
/**
* Retry a promise with exponential backoff.
* ```ts
const prm = new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('Promise error'));
}, 1000);
});
const configuration: ResolveRetryConfig = {
timeoutTime: 5000, // set timeout to fail the promise and retry, default is 0
useJitter: true, // backoff strategy with random + exponantial delay, default is true
retryStrategy: {
initialInterval: 1000, // ms
maxRetries: 3,
maxInterval: 10000, // ms
shouldRetry: (error) => true, // check if retry needed, default is always true
}
}
const res = await resolveWithRetry(prm, configuration);
* ```
* @param promise - Promise to resolve
* @param config - Configuration for retry, can be number as the initial interval, OR ResolveRetryConfig
* @returns Resolved value of the promise with type T (Generic)
*/
export declare function resolveWithRetry<T = any>(promise: Promise<T> | any, config: ResolveRetryConfig | number): Promise<T>;
//# sourceMappingURL=resolve-retry.d.ts.map