LogoPear Docs

bare-abort-controller

Abort controller support for Bare

Documented against v1.1.2
stable

bare-abort-controller — Abort controller support for Bare.

npm i bare-abort-controller

Usage

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()

Create a new AbortController with a fresh, unaborted AbortSignal.

abort(reason: any): void

Abort the controller's signal, notifying every listener with the given reason.

Parameters

ParameterTypeDefaultDescription
reasonanyThe reason to abort with; passed to every 'abort' listener and exposed as the signal's reason. Defaults to an AbortError when omitted.

signal: AbortSignal

The AbortSignal linked to this controller.

AbortSignal

aborted: boolean

Whether the signal has been aborted.

AbortSignal.abort(reason: any): AbortSignal

Return a new AbortSignal that is already aborted with the given reason.

Parameters

ParameterTypeDefaultDescription
reasonanyThe reason the returned signal is aborted with. Defaults to an AbortError when omitted.

AbortSignal.any(signals: AbortSignal[]): AbortSignal

Return a new AbortSignal that aborts as soon as any of the given signals abort, with the same reason.

Parameters

ParameterTypeDefaultDescription
signalsAbortSignal[]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

Return a new AbortSignal that aborts with a TimeoutError after ms milliseconds.

Parameters

ParameterTypeDefaultDescription
msnumberThe number of milliseconds to wait before the returned signal aborts with a TimeoutError.

reason: any

The reason the signal was aborted, or undefined if it hasn't been.

throwIfAborted(): void

Throw the signal's abort reason if the signal has been aborted, otherwise do nothing.

toJSON(): { aborted: boolean; reason: any }

Return a plain object with the signal's aborted and reason values.

bare-abort-controller/global

Types

AbortControllerConstructor

type AbortControllerConstructor = typeof abort.AbortController

AbortSignalConstructor

type AbortSignalConstructor = typeof abort.AbortSignal

See also

On this page