Expose the underlying cancel promise for code that needs to observe cancellation directly. The returned promise rejects with the cancel error and never resolves.
Reject all pending and future guard()s on this signal with
DOMException(reason, "AbortError"). Idempotent: subsequent calls
are silent no-ops, so callers can safely cancel a signal that may
already have been cancelled.
Optionalreason: stringRace p against this signal. If p is a Future, drive cancellation by
rejecting the Future on cancel() — that propagates through the API
client to abort the wire request. Otherwise fall back to Promise.race
(the work keeps running unobserved).
If cancel() is called after the input already settled, the resolved
value flows through unchanged: Future.reject is idempotent post-settle,
and Promise.race only honors the first settlement.
Caller-side cancellation primitive for
Promise<T>/Future<T>-shaped APIs.guard(p)returns a promise that adoptsp's settlement unlesscancel()fires first, in which case it rejects withDOMException("...", "AbortError").The behavior depends on the input:
Future<T>(the runtime shape returned by everyapis.*method): on cancel,guardrejects the Future directly.ApiClient.callWithOptionsobserves that rejection and aborts the underlyingfetch, so the request is dropped on the wire.plain
Promise<T>:Promise.raceagainst the cancel signal. The underlying work keeps running and the result is read but unobserved.Per-operation signals (search-as-you-type debounce, "stop loading" buttons) construct their own
CancelSignalinstances and callcancel()directly.