Skip to content

Commit 06887a2

Browse files
committed
docs: clarify naming and event model differences
1 parent 66cc960 commit 06887a2

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ Targets:
1414

1515
Not a drop‑in polyfill. It’s intentionally smaller and simpler. Key differences from the web standard:
1616

17-
- Renamed types: `AbortController``AbortControllerLite` (interface `AbortControllerLike`); `AbortSignal``AbortSignalLite` (interface `AbortSignalLike`).
18-
1917
- No global patching: this library never defines or mutates global AbortController/AbortSignal; import what you need.
18+
- `AbortController``AbortControllerLite` (interface `AbortControllerLike`).
19+
- `AbortSignal``AbortSignalLite` (interface `AbortSignalLike`).
2020

2121
- Event model
2222
- No EventTarget. Listeners are plain functions, invoked as `listener.call(signal)` with no Event object.
23-
- No `onabort` property, no options (`once`, `signal`) to `addEventListener`, no `dispatchEvent`.
23+
- No `onabort` property, no options (`once`, `signal`, `capture`, et c.) to `addEventListener`, no `dispatchEvent`.
2424
- After the first abort we clear listeners to save memory; manual re‑dispatch isn’t supported. Effectively behaves like `{ once: true }` because an abort happens at most once and listeners are removed.
25+
- Listeners removed during an abort are not invoked; this matches the behavior of DOM event dispatch. But listeners added during an abort may be invoked if added before we finish invoking existing listeners, this differs from DOM behavior.
2526

2627
- Errors and `reason`
2728
- We use lightweight `Error` subclasses (`AbortError`, `TimeoutError`), not `DOMException`.
2829
- `throwIfAborted()` throws the stored `reason` as‑is; avoid relying on `instanceof DOMException`. Prefer checking by name (e.g., `err instanceof Error && err.name === 'AbortError'`).
2930

3031
- `AbortSignalLite.any(iterable)` memory semantics
3132
- Immediate: if any input is already aborted, the result aborts immediately with that `reason`.
32-
- Standard engines maintain internal weak source/dependent lists so combined signals don’t keep inputs alive and vice‑versa.
33+
- Native engines maintain internal weak source/dependent lists so combined signals don’t keep inputs alive and vice‑versa.
3334
- In pure JS we can’t mirror that precisely: we must attach strong listeners to each source and close over the combined signal. We intentionally avoid `WeakRef`/`FinalizationRegistry` to keep size/complexity low.
3435
- Consequence: if you drop all references to the combined signal before any source aborts, the sources still hold listeners that keep the combined signal (and its captured array) alive. Cleanup only happens when one source aborts.
3536
- Practical guidance: use `any()` for short‑lived operations; avoid creating many long‑lived combined signals.
@@ -43,7 +44,7 @@ Not a drop‑in polyfill. It’s intentionally smaller and simpler. Key differen
4344

4445
- Types and modules
4546
- ESM‑only package. Use import syntax; `require()` isn’t supported.
46-
- Public types are `AbortControllerLike` and `AbortSignalLike`; they’re compatible with the standard’s surface you typically use (properties/methods listed in typings).
47+
- Public types are `AbortControllerLike` and `AbortSignalLike` — lightweight subsets of the standard API. Anything that accepts an `AbortSignalLike` will also accept a standard `AbortSignal`.
4748
- TypeScript flags direct construction (`new AbortSignalLite()`) as a type error, but nothing prevents it at runtime. The web standard throws here; we rely on discipline — stick to signals from the controller or the static helpers for the intended lifecycle.
4849

4950
If you need exact spec behavior (DOMException types, EventTarget, GC semantics of `any`, timer unref, etc.), use the platform’s built‑ins where available.

0 commit comments

Comments
 (0)