Zap Studio

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:

  • shouldRetry whether to continue retries
  • delayMs how long to wait before next attempt
  • reason optional tag (retry, max-attempts-reached, policy-declined)

RetryDecisionInput

RetryDecisionInput<TError, TData> includes:

  • attempt current attempt number
  • error previous thrown error
  • data previous data value (if your orchestration tracks one)
  • maxAttempts optional orchestrator hint

RetryExhaustedInput

RetryExhaustedInput<TError, TData> includes:

  • attempts total attempts performed
  • error last error
  • data last data value

RetryRunOptions

Used by BaseRetryPolicy.run(...):

  • sleep optional custom delay implementation
  • throwOnExhausted controls 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

On this page