bare-abort-controller
Abort controller support for Bare
bare-abort-controller — Abort controller support for Bare.
npm i bare-abort-controllerUsage
const controller = new AbortController()
const signal = controller.signal
signal.addEventListener('abort', (event) => {
console.log(event)
})
controller.abort(new Error('Operation aborted'))API
AbortController
new AbortController()
Source
Create a new AbortController with a fresh, unaborted AbortSignal.
abort(reason: any): void
Source
Abort the controller's signal, notifying every listener with the given reason.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
reason | any | — | The reason to abort with; passed to every 'abort' listener and exposed as the signal's reason. Defaults to an AbortError when omitted. |
signal: AbortSignal
Source
The AbortSignal linked to this controller.
AbortSignal
aborted: boolean
Source
Whether the signal has been aborted.
AbortSignal.abort(reason: any): AbortSignal
Source
Return a new AbortSignal that is already aborted with the given reason.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
reason | any | — | The reason the returned signal is aborted with. Defaults to an AbortError when omitted. |
AbortSignal.any(signals: AbortSignal[]): AbortSignal
Source
Return a new AbortSignal that aborts as soon as any of the given signals abort, with the same reason.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
signals | AbortSignal[] | — | The signals to observe; the returned signal aborts with the reason of whichever aborts first, or immediately if one is already aborted. |
AbortSignal.timeout(ms: number): AbortSignal
Source
Return a new AbortSignal that aborts with a TimeoutError after ms milliseconds.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
ms | number | — | The number of milliseconds to wait before the returned signal aborts with a TimeoutError. |
reason: any
Source
The reason the signal was aborted, or undefined if it hasn't been.
throwIfAborted(): void
Source
Throw the signal's abort reason if the signal has been aborted, otherwise do nothing.
toJSON(): { aborted: boolean; reason: any }
Source
Return a plain object with the signal's aborted and reason values.
bare-abort-controller/global
Types
AbortControllerConstructor
type AbortControllerConstructor = typeof abort.AbortControllerAbortSignalConstructor
type AbortSignalConstructor = typeof abort.AbortSignalSee also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.