RetryCalculator
Namespace: TypeSafe.AI.Sdk
public static class RetryCalculatorRetry delay calculation and cancellable waits. Mirrors JS retry.ts.
Inheritance: object
Fields
Section titled “Fields”DefaultTimeoutMs
Section titled “DefaultTimeoutMs”public const int DefaultTimeoutMs = 10000Default timeout per attempt in milliseconds.
Value: int
Methods
Section titled “Methods”DelayMs(int, HttpResponseHeaders?, RetryPolicy?, Func<double>?)
Section titled “DelayMs(int, HttpResponseHeaders?, RetryPolicy?, Func<double>?)”public static int DelayMs(int attempt, HttpResponseHeaders? headers = null, RetryPolicy? policy = null, Func<double>? random = null)Calculate the delay in milliseconds for a zero-based retry attempt. Uses an allowed server delay; otherwise uses capped exponential backoff with jitter.
Parameters
| Name | Type | Description |
|---|---|---|
attempt |
int | |
headers |
HttpResponseHeaders | |
policy |
RetryPolicy | |
random |
Func<double> |
Returns: int
IsRetryableStatus(int, RetryPolicy?)
Section titled “IsRetryableStatus(int, RetryPolicy?)”public static bool IsRetryableStatus(int status, RetryPolicy? policy = null)Whether the policy retries an HTTP status code.
Parameters
| Name | Type | Description |
|---|---|---|
status |
int | |
policy |
RetryPolicy |
Returns: bool
ParseRetryAfter(HttpResponseHeaders, DateTimeOffset?)
Section titled “ParseRetryAfter(HttpResponseHeaders, DateTimeOffset?)”public static int? ParseRetryAfter(HttpResponseHeaders headers, DateTimeOffset? now = null)Parse retry-after-ms or Retry-After into milliseconds, preferring retry-after-ms.
Returns null when neither header contains a valid delay.
Parameters
| Name | Type | Description |
|---|---|---|
headers |
HttpResponseHeaders | |
now |
DateTimeOffset? |
Returns: int?
SleepAsync(int, CancellationToken)
Section titled “SleepAsync(int, CancellationToken)”public static Task SleepAsync(int milliseconds, CancellationToken cancellationToken = default)Wait <code class=“paramref”>milliseconds</code>, throwing OperationCanceledException on cancellation.
Parameters
| Name | Type | Description |
|---|---|---|
milliseconds |
int | |
cancellationToken |
CancellationToken |
Returns: Task
MIT · Copyright (c) Dario Kondratiuk. · not affiliated with TypeSafe beyond being a client of the public API