Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbortController

Package version

An AbortController provides an AbortSignal and the associated controls to signal that an asynchronous operation should be aborted.

example

// Abort an operation when another event fires const controller = new AbortController(); const signal = controller.signal; doAsyncWork(signal); button.addEventListener('click', () => controller.abort());

example

// Share aborter cross multiple operations in 30s // Upload the same data to 2 different data centers at the same time, // abort another when any of them is finished const controller = AbortController.withTimeout(30 * 1000); doAsyncWork(controller.signal).then(controller.abort); doAsyncWork(controller.signal).then(controller.abort);

example

// Cascaded aborting // All operations can't take more than 30 seconds const aborter = Aborter.timeout(30 * 1000);

// Following 2 operations can't take more than 25 seconds await doAsyncWork(aborter.withTimeout(25 * 1000)); await doAsyncWork(aborter.withTimeout(25 * 1000));

export
class

AbortController

implements

{AbortSignalLike}

Hierarchy

  • AbortController

Index

Constructors

Properties

Methods

Constructors

constructor

  • constructor

    Parameters

    • Optional parentSignals: AbortSignalLike[]

      The AbortSignals that will signal aborted on the AbortSignal associated with this controller.

    Returns AbortController

  • constructor

    Parameters

    • Rest ...parentSignals: AbortSignalLike[]

      The AbortSignals that will signal aborted on the AbortSignal associated with this controller.

    Returns AbortController

Properties

signal

signal: AbortSignal

The AbortSignal associated with this controller that will signal aborted when the abort method is called on this controller.

readonly
type

{AbortSignal}

memberof

AbortController

Methods

abort

  • abort(): void
  • Signal that any operations passed this controller's associated abort signal to cancel any remaining work and throw an AbortError.

    memberof

    AbortController

    Returns void

Static timeout

  • Creates a new AbortSignal instance that will abort after the provided ms.

    static
    params

    {number} ms Elapsed time in milliseconds to trigger an abort.

    Parameters

    • ms: number

    Returns AbortSignal

Generated using TypeDoc