包详细信息

extra-abort

BlackGlory14.8kMIT0.4.0

sh npm install --save extra-abort # or yarn add extra-abort

自述文件

extra-abort

Install

npm install --save extra-abort
# or
yarn add extra-abort

API

AbortController, AbortSignal

The WHATWG AbortController and AbortSignal.

AbortError

class AbortError extends CustomError {}

It is not the real AbortError of fetch, but you can do err instance AbortError like it is, because it can recognizes other errors that match the pattern of AbortError.

LinkedAbortController

class LinkedAbortController extends AbortController {
  constructor(signal: AbortSignal)
}

It is a special AbortController that takes an AbortSignal as a parameter. It will abort itself when its parameter signal aborts, you can make it abort by calling its abort method too.

timeoutSignal

function timeoutSignal(ms: number): AbortSignal

It will abort after ms milliseconds.

await fetch('http://example.com', { signal: timeoutSignal(5000) })

withAbortSignal

/**
 * @throws {AbortError}
 */
function withAbortSignal<T>(signal: AbortSignal | Falsy, fn: () => PromiseLike<T>): Promise<T>

If AbortSignal is aborted, the promise will be rejected with AbortError.

raceAbortSignals

function raceAbortSignals(signals: Array<AbortSignal | Falsy>): AbortSignal

The Promise.race function for AbortSignal.

isAbortSignal

function isAbortSignal(val: unknown): val is AbortSignal

lastCallOnly

function lastCallOnly<T, Args extends unknown[]>(
  fn: (...args: [...args: Args, signal: AbortSignal]) => PromiseLike<T>
): (...args: [...args: Args, signal: AbortSignal | Falsy]) => Promise<T>

更新日志

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.4.0 (2024-12-10)

⚠ BREAKING CHANGES

  • Node.js v16 => v18.17.0

Features

  • add support for custom reasons (b615bbb)

0.3.10 (2024-12-02)

Features

0.3.9 (2023-12-30)

Features

0.3.8 (2023-12-29)

Features

  • withAbortSignal: allow signal to be falsy (c9cb054)

0.3.7 (2023-06-10)

Bug Fixes

0.3.6 (2023-04-03)

Features

0.3.5 (2023-04-02)

Features

0.3.4 (2023-03-26)

0.3.3 (2023-03-24)

0.3.2 (2023-03-09)

Features

  • add LinkedAbortController (fb83e55)

0.3.1 (2023-01-22)

0.3.0 (2023-01-22)

⚠ BREAKING CHANGES

  • CommonJS => ESM

  • commonjs => esm (25d9ca2)

0.2.1 (2023-01-21)

0.2.0 (2022-11-01)

⚠ BREAKING CHANGES

  • The minimal version of Node.js is v16

  • improve AbortError, replace objects with native objects (f25c09a)

0.1.4 (2022-10-21)

0.1.3 (2022-08-01)

0.1.2 (2022-03-19)

0.1.1 (2022-02-03)

Features

0.1.0 (2021-12-17)

Features