@cloudflare/actors
Version:
An easier way to build with Cloudflare Durable Objects
63 lines • 3.33 kB
TypeScript
export declare function RetryConditionAlways(): boolean;
export declare function RetryConditionNever(): boolean;
/**
* @param fn The function to call for each attempt. Receives the attempt number.
* @param isRetryable The function to call to determine if the error is retryable. Receives the error and the next attempt number.
* @param options The options for the retry strategy.
* @param options.baseDelayMs Number of milliseconds to use as multiplier for the exponential backoff.
* @param options.maxDelayMs Maximum number of milliseconds to wait.
* @param options.verbose If true, logs the error and attempt number to the console.
* @returns The result of the `fn` function or propagates the last error thrown once `isRetryable` returns false or all retries failed.
*/
export declare function tryWhile<T>(fn: (attempt: number) => Promise<T>, isRetryable: (err: unknown, nextAttempt: number) => boolean, options?: {
baseDelayMs?: number;
maxDelayMs?: number;
verbose?: boolean;
}): Promise<T>;
export type TryNOptions = {
/**
* @param err Error thrown by the function.
* @param nextAttempt Number of next attempt to make.
* @returns Returns true if the error and nextAttempt number is retryable.
*/
isRetryable?: (err: unknown, nextAttempt: number) => boolean;
/**
* Number of milliseconds to use as multiplier for the exponential backoff.
*/
baseDelayMs?: number;
/**
* Maximum number of milliseconds to wait.
*/
maxDelayMs?: number;
/**
* If true, logs the error and attempt number to the console.
*/
verbose?: boolean;
};
/**
* @param n Number of total attempts to make.
* @param fn The function to call for each attempt. Receives the attempt number.
* @param options The options for the retry strategy.
* @param options.isRetryable The function to call to determine if the error is retryable. Receives the error and the next attempt number.
* @param options.baseDelayMs Number of milliseconds to use as multiplier for the exponential backoff.
* @param options.maxDelayMs Maximum number of milliseconds to wait.
* @param options.verbose If true, logs the error and attempt number to the console.
* @returns The result of the `fn` function or propagates the last error thrown once `isRetryable` returns false or all retries failed.
*/
export declare function tryN<T>(n: number, fn: (attempt: number) => Promise<T>, options?: TryNOptions): Promise<T>;
/**
* Returns the number of milliseconds to wait before retrying a request.
* See the "Full Jitter" approach in https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/.
* @param attempt The number of attempts so far.
* @param baseDelayMs Number of milliseconds to use as multiplier for the exponential backoff.
* @param maxDelayMs Maximum number of milliseconds to wait.
* @returns Milliseconds to wait before retrying.
*/
export declare function jitterBackoff(attempt: number, baseDelayMs: number, maxDelayMs: number): number;
/**
* Returns true if the given error is retryable according to the Durable Object error handling.
* See https://developers.cloudflare.com/durable-objects/best-practices/error-handling/.
* @param err
*/
export declare function isErrorRetryable(err: unknown): boolean;
//# sourceMappingURL=retries.d.ts.map