> ## Documentation Index
> Fetch the complete documentation index at: https://acme-c84a37e5.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Retry Logic

> Reintentos con delay, jitter y estrategias de backoff

## Opciones principales

* `retries`: cantidad de reintentos
* `retryDelay`: número, función o basada en intento y último error
* `jitter`: aleatoriedad para evitar thundering herd
* `backoffStrategy`: `linear`, `exponential`, `fibonacci` o función
* `maxDelay`: límite superior del delay
* `shouldRetry`: decide si continuar reintentando
* `onRetry`: observabilidad por intento

## Ejemplo básico

```typescript theme={null}
import { run } from "tryo";

const r = await run(() => fetch("/api"), {
  retries: 3,
  retryDelay: 300,
  jitter: 0.5,
  backoffStrategy: "exponential",
});
```

## Delay dinámico

```typescript theme={null}
const r = await run(() => fetch("/api"), {
  retries: 5,
  retryDelay: (attempt) => attempt * 200,
  maxDelay: 2000,
});
```

## Control de reintentos con `shouldRetry`

```typescript theme={null}
const r = await run(() => fetch("/api"), {
  retries: 5,
  shouldRetry: (attempt, error, ctx) => error.code !== "ABORTED" && ctx.elapsedTime < 5000,
});
```

## Observabilidad con `onRetry`

```typescript theme={null}
const r = await run(() => fetch("/api"), {
  retries: 3,
  onRetry: (attempt, error, nextDelay) => {
    console.log(attempt, error.code, nextDelay);
  },
});
```
