Zap Studio

Overview

A composable retry package with policy classes, a built-in runner, and structured terminal errors.

retry gives you reusable retry policies and a built-in runner so you can add resilient retries without rewriting orchestration loops.

Why retry?

Most retry implementations end up duplicating the same logic:

  • track attempts
  • catch errors
  • calculate delay
  • sleep
  • throw a final terminal error

@zap-studio/retry centralizes that flow in policy classes like ExponentialBackoff and FixedDelay.

What You Get

  • Built-in policies with fixed and exponential delay strategies.
  • A shared runner via BaseRetryPolicy.run(...).
  • Structured terminal errors through RetryError.
  • Non-throw mode for callers that prefer result objects.
  • Custom policy contracts when the built-in policies are not enough.

Core Concepts

  • Policy decides if and when to retry with next(...).
  • Runner executes attempts, catches failures, sleeps, and stops.
  • Terminal error is shaped by onExhausted(...).

Built-in Policies

  • Use FixedDelay when every retry should wait the same amount of time.
  • Use ExponentialBackoff when retries target shared services or transient network failures.
Edit on GitHub

Last updated on

On this page