Skip to content

Abort & Timeout

AsyncLoader supports manual abort and per-attempt loading timeouts, both penetrating to the underlying request via the internal signal.

Per-attempt timeout

typescript
const loader = new AsyncLoader(
    (args) => fetch("/api/data", { signal: args.abortSignal }),
    { timeout: 5_000 } // 5-second timeout per attempt
);

loader.abort(); // abort the in-flight request, penetrating to fetch

Error types

Timeout and manual abort produce different error types:

  • Timeout final failure (retries exhausted or retry disabled) → rejects with TimeoutError
  • Manual abort() / external abortSignal → rejects with AbortError
  • Business errors → the original error is propagated as-is

External abort signal

Pass an external AbortSignal via the abortSignal option; when triggered it aborts loading and does not trigger retry:

typescript
const controller = new AbortController();
const loader = new AsyncLoader(
    (args) => fetch("/api/data", { signal: args.abortSignal }),
    { abortSignal: controller.signal, retry: 3 },
);

controller.abort(); // linked abort, no retry

Manual abort does not retry

Neither loader.abort() nor an external abortSignal triggers a Retry; only timeouts and business errors do.

Released under the MIT License.