Types
Understand retry policy contracts, generic inputs, and runner options.
All retry contracts are exposed from @zap-studio/retry/types.
Core Types
import type {
RetryDecision,
RetryDecisionInput,
RetryExhaustedInput,
RetryPolicy,
RetryRunOptions,
RetryRunResult,
} from "@zap-studio/retry/types";Generic Contracts
The package is transport-agnostic and generic over error/data shapes:
RetryPolicy<TError, TData>RetryDecisionInput<TError, TData>RetryExhaustedInput<TError, TData>
Example:
type HttpPolicy = RetryPolicy<TypeError, Response>;RetryDecision
RetryDecision includes:
shouldRetrywhether to continue retriesdelayMshow long to wait before next attemptreasonoptional tag (retry,max-attempts-reached,policy-declined)
RetryDecisionInput
RetryDecisionInput<TError, TData> includes:
attemptcurrent attempt numbererrorprevious thrown errordataprevious data value (if your orchestration tracks one)maxAttemptsoptional orchestrator hint
RetryExhaustedInput
RetryExhaustedInput<TError, TData> includes:
attemptstotal attempts performederrorlast errordatalast data value
RetryRunOptions
Used by BaseRetryPolicy.run(...):
sleepoptional custom delay implementationthrowOnExhaustedcontrols throw (true, default) vs result mode (false)
const options: RetryRunOptions = {
throwOnExhausted: false,
sleep: async (ms) => {
await new Promise((resolve) => setTimeout(resolve, ms));
},
};When throwOnExhausted is false, run(...) returns RetryRunResult<T>.
Edit on GitHub
Last updated on