Saltar al contenido principal

Reusar una instancia

import trybox from "trybox";
export const runner = trybox({ ignoreAbort: true });

Centralizar mapError

const runner = trybox({ mapError: (e) => ({ ...e, message: e.message }) });

Delimitar reintentos

await runner.run(() => fetch("/api"), {
  retries: 3,
  shouldRetry: (attempt, e, ctx) => e.code !== "ABORTED" && ctx.elapsedTime < 5000,
});

Usar jitter y backoff

await runner.run(() => fetch("/api"), { retryDelay: 300, jitter: 0.5, backoffStrategy: "exponential" });