1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export class AbortController implements AbortSignal {
|
11 | private isAborted: boolean = false;
|
12 | public onabort: (() => void) | null = null;
|
13 |
|
14 | public abort() {
|
15 | if (!this.isAborted) {
|
16 | this.isAborted = true;
|
17 | if (this.onabort) {
|
18 | this.onabort();
|
19 | }
|
20 | }
|
21 | }
|
22 |
|
23 | get signal(): AbortSignal {
|
24 | return this;
|
25 | }
|
26 |
|
27 | get aborted(): boolean {
|
28 | return this.isAborted;
|
29 | }
|
30 | }
|
31 |
|
32 | /** Represents a signal that can be monitored to determine if a request has been aborted. */
|
33 | export interface AbortSignal {
|
34 | /** Indicates if the request has been aborted. */
|
35 | aborted: boolean;
|
36 | /** Set this to a handler that will be invoked when the request is aborted. */
|
37 | onabort: (() => void) | null;
|
38 | }
|
39 |
|
\ | No newline at end of file |