1 | import { Observable } from '../data/observable';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export default class AbortSignal extends Observable {
|
7 | |
8 |
|
9 |
|
10 | constructor() {
|
11 | super();
|
12 | }
|
13 | |
14 |
|
15 |
|
16 | get aborted() {
|
17 | const aborted = abortedFlags.get(this);
|
18 | if (typeof aborted !== 'boolean') {
|
19 | throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? 'null' : typeof this}`);
|
20 | }
|
21 | return aborted;
|
22 | }
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 | export function createAbortSignal() {
|
28 | const signal = new AbortSignal();
|
29 | abortedFlags.set(signal, false);
|
30 | return signal;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | export function abortSignal(signal) {
|
36 | if (abortedFlags.get(signal) !== false) {
|
37 | return;
|
38 | }
|
39 | abortedFlags.set(signal, true);
|
40 | signal.notify({ eventName: 'abort', type: 'abort' });
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 | const abortedFlags = new WeakMap();
|
46 |
|
47 | Object.defineProperties(AbortSignal.prototype, {
|
48 | aborted: { enumerable: true },
|
49 | });
|
50 |
|
51 | if (typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol') {
|
52 | Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
|
53 | configurable: true,
|
54 | value: 'AbortSignal',
|
55 | });
|
56 | }
|
57 |
|
\ | No newline at end of file |