Skip to content

ExponentialBackoff

Namespace: Vercel.AI.ProviderUtils

public static class ExponentialBackoff

Retries a failed operation with exponential backoff. Abort errors are rethrown. The first non-retryable error is rethrown without wrapping.

Inheritance: object

View source

RetryAsync<T>(Func<Task<T>>, Func<Exception, Task<bool>>, RetryOptions?, CancellationToken)

Section titled “RetryAsync<T>(Func<Task<T>>, Func<Exception, Task<bool>>, RetryOptions?, CancellationToken)”
public static Task<T> RetryAsync<T>(Func<Task<T>> action, Func<Exception, Task<bool>> shouldRetry, RetryOptions? options = null, CancellationToken cancellationToken = default)

Runs <code class=“paramref”>action</code> until it succeeds or retries are exhausted.

Type parameters

Name Description
T

Parameters

Name Type Description
action Func<Task<T>>
shouldRetry Func<Exception, Task<bool>>
options RetryOptions
cancellationToken CancellationToken

Returns: Task<T>

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product