Table of Contents

Class RetryPolicy

Namespace
Velvet
Assembly
Velvet.Docs.dll

Retries a failed async operation: TanStack Query's retry / retryDelay pair as a value an operation opts into. Retry hands one to a mutation; RunAsync<T>(Func<CancellationToken, VelvetTask<T>>, CancellationToken) wraps another operation, such as a Use<T>(Func<CancellationToken, VelvetTask<T>>, object?) loader.

public sealed record RetryPolicy
Inheritance
object
RetryPolicy

Remarks

After the operation fails, RetryDelay is asked for the wait and then Retry whether to retry, as TanStack's retryer asks them, and an accepted failure is retried once the wait is over and NetworkMode allows. The last failure is the one the caller receives. Once the token passed to RunAsync<T>(Func<CancellationToken, VelvetTask<T>>, CancellationToken) is cancelled no further attempt starts: a failure then propagates as it is, and a cancellation during a wait rejects as cancelled. An System.OperationCanceledException the operation throws while the token is not cancelled is a failure like any other.

Properties

IsFocused

Reads whether the application is visible, as TanStack's focus manager reads the page's visibility. A retry that is due while it is not waits until it is, in every NetworkMode. When null, IsVisible, which defaults to a reading of the platform's window state, not of its focus. Read on the main thread.

IsOnline

Reads whether the device is online, for NetworkMode. When null, IsOnline, which defaults to Application.internetReachability not being NotReachable. Read on the main thread.

NetworkMode

Whether going offline pauses the operation, as TanStack's networkMode option. Defaults to Online.

Retry

Which failures are retried, as TanStack's retry option. Defaults to 3 retries, TanStack Query's default for a query.

RetryDelay

The wait before the next attempt, as TanStack's retryDelay option: a constant, or a function of the number of failures before this one and this failure's exception. Defaults to one second doubled at each retry, capped at thirty seconds.

Wait

Waits out a RetryDelay, and is handed the token passed to RunAsync<T>(Func<CancellationToken, VelvetTask<T>>, CancellationToken). When null, wall-clock time measured by System.Diagnostics.Stopwatch on the main thread, checked once per frame and for at least one frame, which Time.timeScale does not slow. Supply one to wait on game time.

Methods

RunAsync<T>(Func<CancellationToken, VelvetTask<T>>, CancellationToken)

Runs operation, retrying it under this policy, and returns the first successful attempt's result. Each attempt receives cancellationToken.