• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alessiofrittoli / abort-controller / 14793547768

02 May 2025 10:32AM UTC coverage: 100.0%. Remained the same
14793547768

push

github

alessiofrittoli
release v0.1.0

1 of 1 branches covered (100.0%)

Branch coverage included in aggregate %.

4 of 4 relevant lines covered (100.0%)

2.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/index.ts
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
import { AbortError, type AbortErrorOptions } from '@alessiofrittoli/exception/abort'
1✔
3
import type { ErrorCode } from '@alessiofrittoli/exception/code'
4

5
/**
6
 * A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object.
7
 */
8
export interface AbortSignal<TCode = ErrorCode> extends globalThis.AbortSignal
9
{
10
        readonly reason: AbortError<string, TCode>
11
        onabort: ( ( this: AbortSignal, event: Event ) => unknown ) | null
12
        addEventListener<K extends keyof AbortSignalEventMap>( type: K, listener: ( this: AbortSignal, ev: AbortSignalEventMap[ K ] ) => any, options?: boolean | AddEventListenerOptions ): void
13
    addEventListener( type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions ): void
14
    removeEventListener<K extends keyof AbortSignalEventMap>( type: K, listener: ( this: AbortSignal, ev: AbortSignalEventMap[ K ] ) => any, options?: boolean | EventListenerOptions ): void
15
    removeEventListener( type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions ): void
16
}
17

18

19
/**
20
 * A controller object that allows you to abort one or more DOM requests as and when desired.
21
 * 
22
 * @template TCode A custom type assigned to the `AbortError.code`. Default: {@link ErrorCode}.
23
 * 
24
 * @extends globalThis.AbortController
25
 */
26
export class AbortController<TCode = ErrorCode> extends globalThis.AbortController
1✔
27
{
28
        readonly signal: AbortSignal<TCode>
29

30
        constructor()
31
        {
32
                super()
4✔
33
        }
34

35

36
        /**
37
         * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
38
         * 
39
         * @param reason        ( Optional ) The abort reason. This will be set to `AbortError.message`.
40
         * @param options        ( Optioanl ) Custom `AbortError` options.
41
         */
42
        abort( reason: string = 'The operation was aborted.', options?: AbortErrorOptions<TCode> )
1✔
43
        {
44
                super.abort( new AbortError<string, TCode>( reason, options ) )
3✔
45
        }
46
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc