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.

Example

// Abort without timeout
await blockBlobURL.upload(Aborter.none, buf, buf.length);

Example

// Abort container create in 1000ms
await blockBlobURL.upload(Aborter.timeout(1000), buf, buf.length);

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 aborter = Aborter.timeout(30 * 1000);
blockBlobURL1.upload(aborter, buf, buf.length).then(aborter.abort);
blockBlobURL2.upload(aborter, buf, buf.length).then(aborter.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 blockBlobURL.upload(aborter.withTimeout(25 * 1000), buf, buf.length);
await blockBlobURL.upload(aborter.withTimeout(25 * 1000), buf, buf.length);

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.

dispatchEvent()
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 father node of the new instance. When current or father Aborter node triggers timeout event, all children nodes 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, null | string | number | boolean)

Create and return a new Aborter instance, which will be appended as a child node of current Aborter. Current Aborter instance becomes father node of the new instance. When current or father 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: null | (this: AbortSignalLike, ev: any) => any

Property Value

null | (this: AbortSignalLike, ev: any) => 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

dispatchEvent()

function dispatchEvent(): boolean

Returns

boolean

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): undefined | null | string | number | boolean

Parameters

key

string

Returns

undefined | null | string | number | boolean

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 father node of the new instance. When current or father Aborter node triggers timeout event, all children nodes 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, null | string | number | boolean)

Create and return a new Aborter instance, which will be appended as a child node of current Aborter. Current Aborter instance becomes father node of the new instance. When current or father 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?: null | string | number | boolean): Aborter

Parameters

key

string

value

null | string | number | boolean

Returns