# `Playwright.AbortSignal`
[🔗](https://github.com/ftes/playwright_ex/blob/v1.65.0-rc.3/lib/playwright/abort_signal.ex#L1)

The DOM `AbortSignal` of the `signal:` options, from a `Playwright.AbortController`:

    controller = Playwright.AbortController.new()
    task = Task.async(fn -> Playwright.Locator.click(button, signal: Playwright.AbortController.signal(controller)) end)
    Playwright.AbortController.abort(controller, "user cancelled")
    {:error, %Playwright.AbortError{cause: "user cancelled"}} = Task.await(task)

Runtime support (not ported from upstream): the part of the DOM class that Playwright uses
(`aborted`, `reason`, `throwIfAborted`, `abort` listeners). A signal is global, as in JS: it
belongs to no driver and works with calls on any. Its state lives in a public ETS table of the
application, so reads are lock-free from any process, and any process aborts.

Listeners run synchronously in the aborting process (as `dispatchEvent` runs them), so they
must not block: the client's listeners only send messages. A listener added after the abort
never runs (as in the DOM).

Deviation: a signal's rows (its reason, its listeners) are freed when the process that created
it exits; JS frees them with the signal.

# `t`

```elixir
@type t() :: %Playwright.AbortSignal{id: term()}
```

An abort signal (`Playwright.AbortController.signal/1`).

# `aborted`

```elixir
@spec aborted(t()) :: boolean()
```

`signal.aborted`: whether the controller aborted.

# `add_event_listener`

```elixir
@spec add_event_listener(t(), :abort | String.t(), (-&gt; term()), map() | keyword()) ::
  :ok
```

`signal.addEventListener('abort', listener, options)`: `listener` (a 0-arity function) runs
in the aborting process when the signal aborts (see the moduledoc). A listener is added once
(equal functions are the same listener); `once: true` is implied, a signal aborts once.

# `reason`

```elixir
@spec reason(t()) :: term()
```

`signal.reason`: the reason given to `Playwright.AbortController.abort/2`, `nil` while not aborted.

# `remove_event_listener`

```elixir
@spec remove_event_listener(t(), :abort | String.t(), (-&gt; term())) :: :ok
```

`signal.removeEventListener('abort', listener)`.

# `throw_if_aborted`

```elixir
@spec throw_if_aborted(t()) :: :ok
```

`signal.throwIfAborted()`: raises the reason when aborted, if it is an exception, else an
`AbortError` with the reason as its `cause` (JS throws any value).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
