Header menu logo TDesu.FSharp

Retry Module

Retry combinators with exponential backoff and fixed delay strategies.

Functions and values

Function or value Description

Retry.tryWithBackoff maxRetries baseDelay ct f

Full Usage: Retry.tryWithBackoff maxRetries baseDelay ct f

Parameters:
    maxRetries : int - Maximum number of retry attempts.
    baseDelay : TimeSpan - Initial delay; doubles after each failed attempt.
    ct : CancellationToken - Cancellation token to abort the retry loop.
    f : unit -> Task<'T> - Async factory to invoke on each attempt.

Returns: Task<Result<'T, exn>> Ok(value) on success, Error(exn) after all retries fail.

Retries f with exponential backoff, returning Result instead of throwing.

maxRetries : int

Maximum number of retry attempts.

baseDelay : TimeSpan

Initial delay; doubles after each failed attempt.

ct : CancellationToken

Cancellation token to abort the retry loop.

f : unit -> Task<'T>

Async factory to invoke on each attempt.

Returns: Task<Result<'T, exn>>

Ok(value) on success, Error(exn) after all retries fail.

Retry.withBackoff maxRetries baseDelay ct f

Full Usage: Retry.withBackoff maxRetries baseDelay ct f

Parameters:
    maxRetries : int - Maximum number of retry attempts.
    baseDelay : TimeSpan - Initial delay; doubles after each failed attempt.
    ct : CancellationToken - Cancellation token to abort the retry loop.
    f : unit -> Task<'T> - Async factory to invoke on each attempt.

Returns: Task<'T>

Retries f up to maxRetries times with exponential backoff. Base delay doubles each attempt. Throws the last exception if all attempts fail.

maxRetries : int

Maximum number of retry attempts.

baseDelay : TimeSpan

Initial delay; doubles after each failed attempt.

ct : CancellationToken

Cancellation token to abort the retry loop.

f : unit -> Task<'T>

Async factory to invoke on each attempt.

Returns: Task<'T>
Exception Re-raises the last exception after all retries are exhausted.
Example

 let! result = Retry.withBackoff 3 (TimeSpan.FromSeconds 1.) (fun () -> httpClient.GetAsync(url))

Retry.withDelay maxRetries delay ct f

Full Usage: Retry.withDelay maxRetries delay ct f

Parameters:
Returns: Task<'T>

Retries f with a fixed delay between attempts. Maximum number of retry attempts. Fixed delay between each attempt. Cancellation token to abort the retry loop. Async factory to invoke on each attempt.

maxRetries : int
delay : TimeSpan
ct : CancellationToken
f : unit -> Task<'T>
Returns: Task<'T>

Type something to start searching.