LogoPear Docs

bare-abort-controller

Abort controller support for Bare

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

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

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

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

ParameterTypeDefaultDescription
reasonanyThe 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

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

Source

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

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.AbortController
Source

AbortSignalConstructor

type AbortSignalConstructor = typeof abort.AbortSignal
Source

See also

On this page