Skip to content

Async

The cancellation that does not cancel

An abort signal read once, before the work starts, and never again.

12 minutes · AbortSignal · cooperative cancellation · checking after resume

A signal is only true when you read it

Cancellation in JavaScript is cooperative. Nothing stops your function; a flag is set, and it is your job to notice. Code that checks the flag once, at the top, has built something that can be cancelled only in the instant before it starts.

The interesting case is the one where the cancellation arrives *during* the await — which is the overwhelmingly common case, because the await is where all the time goes. On the far side, the function resumes and carries on writing.

Everything you do here stays in this browser.