Aborter class

An aborter instance implements AbortSignal interface, can abort HTTP requests.

  • Call Aborter.none to create a new Aborter instance without timeout.
  • Call Aborter.timeout() to create a new Aborter instance with timeout.

For an existing instance aborter:

  • Call aborter.withTimeout() to create and return a child Aborter instance with timeout.
  • Call aborter.withValue(key, value) to create and return a child Aborter instance with key/value pair.
  • Call aborter.abort() to abort current instance and all children instances.
  • Call aborter.getValue(key) to search and get value with corresponding key from current aborter to all parents.

Properties

aborted

Status of whether aborted or not.

none

Creates a new Aborter instance without timeout.

onabort

onabort event listener.

Methods

abort()

Trigger abort event immediately, the onabort and all abort event listeners will be triggered. Will try to trigger abort event for all children Aborter nodes.

  • If there is a timeout, the timer will be cancelled.
  • If aborted is true, nothing will happen.
addEventListener("abort", (this: AbortSignalLike, ev: any) => any)

Added new "abort" event listener, only support "abort" event.

getValue(string)

Find out latest value with corresponding key in the chain of [current node] -> [parent node] -> [grand parent node] -> ... -> [root node]. If key is not found, undefined will be returned.

removeEventListener("abort", (this: AbortSignalLike, ev: any) => any)

Remove "abort" event listener, only support "abort" event.

timeout(number)

Creates a new Aborter instance with timeout in milliseconds. Set parameter timeout to 0 will not create a timer.

withTimeout(number)

Create and return a new Aborter instance, which will be appended as a child node of current Aborter. Current Aborter instance becomes parent node of the new instance. When current or parent Aborter node triggers timeout event, all children node's abort event will be triggered too. When timeout parameter (in millisecond) is larger than 0, the abort event will be triggered when timeout. Otherwise, call abort() method to manually abort.

withValue(string, string | number | boolean | null)

Create and return a new Aborter instance, which will be appended as a child node of current Aborter. Current Aborter instance becomes parent node of the new instance. When current or parent Aborter node triggers timeout event, all children nodes abort event will be triggered too. Immutable key value pair will be set into the new created Aborter instance. Call getValue() to find out latest value with corresponding key in the chain of [current node] -> [parent node] and [grand parent node]....

Property Details

aborted

Status of whether aborted or not.

aborted: boolean

Property Value

boolean

none

Creates a new Aborter instance without timeout.

static none: Aborter

Property Value

onabort

onabort event listener.

onabort?: (ev?: Event) => any

Property Value

(ev?: Event) => any

Method Details

abort()

Trigger abort event immediately, the onabort and all abort event listeners will be triggered. Will try to trigger abort event for all children Aborter nodes.

  • If there is a timeout, the timer will be cancelled.
  • If aborted is true, nothing will happen.
function abort()

addEventListener("abort", (this: AbortSignalLike, ev: any) => any)

Added new "abort" event listener, only support "abort" event.

function addEventListener(_type: "abort", listener: (this: AbortSignalLike, ev: any) => any)

Parameters

_type

"abort"

Only support "abort" event

listener

(this: AbortSignalLike, ev: any) => any

getValue(string)

Find out latest value with corresponding key in the chain of [current node] -> [parent node] -> [grand parent node] -> ... -> [root node]. If key is not found, undefined will be returned.

function getValue(key: string): string | number | boolean | null | undefined

Parameters

key

string

Returns

string | number | boolean | null | undefined

removeEventListener("abort", (this: AbortSignalLike, ev: any) => any)

Remove "abort" event listener, only support "abort" event.

function removeEventListener(_type: "abort", listener: (this: AbortSignalLike, ev: any) => any)

Parameters

_type

"abort"

Only support "abort" event

listener

(this: AbortSignalLike, ev: any) => any

timeout(number)

Creates a new Aborter instance with timeout in milliseconds. Set parameter timeout to 0 will not create a timer.

static function timeout(timeout: number): Aborter

Parameters

timeout

number

Returns

withTimeout(number)

Create and return a new Aborter instance, which will be appended as a child node of current Aborter. Current Aborter instance becomes parent node of the new instance. When current or parent Aborter node triggers timeout event, all children node's abort event will be triggered too. When timeout parameter (in millisecond) is larger than 0, the abort event will be triggered when timeout. Otherwise, call abort() method to manually abort.

function withTimeout(timeout: number): Aborter

Parameters

timeout

number

Returns

The new Aborter instance created.

withValue(string, string | number | boolean | null)

Create and return a new Aborter instance, which will be appended as a child node of current Aborter. Current Aborter instance becomes parent node of the new instance. When current or parent Aborter node triggers timeout event, all children nodes abort event will be triggered too. Immutable key value pair will be set into the new created Aborter instance. Call getValue() to find out latest value with corresponding key in the chain of [current node] -> [parent node] and [grand parent node]....

function withValue(key: string, value?: string | number | boolean | null): Aborter

Parameters

key

string

value

string | number | boolean | null

Returns