https://github.com/blackglory/extra-abort
🌲
https://github.com/blackglory/extra-abort
browser esm library nodejs npm-package
Last synced: 3 months ago
JSON representation
🌲
- Host: GitHub
- URL: https://github.com/blackglory/extra-abort
- Owner: BlackGlory
- License: mit
- Created: 2021-12-17T08:57:55.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-06-15T16:12:01.000Z (about 1 year ago)
- Last Synced: 2025-06-22T21:42:51.273Z (about 1 year ago)
- Topics: browser, esm, library, nodejs, npm-package
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/extra-abort
- Size: 619 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# extra-abort
## Install
```sh
npm install --save extra-abort
# or
yarn add extra-abort
```
## API
### AbortController, AbortSignal
The WHATWG `AbortController` and `AbortSignal`.
### AbortError
```ts
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
```ts
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
```ts
function timeoutSignal(ms: number): AbortSignal
```
It will abort after `ms` milliseconds.
```ts
await fetch('http://example.com', { signal: timeoutSignal(5000) })
```
### withAbortSignal
```ts
/**
* @throws {AbortError}
*/
function withAbortSignal(signal: AbortSignal | Falsy, fn: () => PromiseLike): Promise
```
If `AbortSignal` is aborted, the promise will be rejected with `AbortError`.
### raceAbortSignals
```ts
function raceAbortSignals(signals: Array): AbortSignal
```
The `Promise.race` function for `AbortSignal`.
### isAbortSignal
```ts
function isAbortSignal(val: unknown): val is AbortSignal
```
### lastCallOnly
```ts
function lastCallOnly(
fn: (...args: [...args: Args, signal: AbortSignal]) => PromiseLike
): (...args: [...args: Args, signal: AbortSignal | Falsy]) => Promise
```