UNPKG

1.24 kBPlain TextView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
4// Rough polyfill of https://developer.mozilla.org/en-US/docs/Web/API/AbortController
5// We don't actually ever use the API being polyfilled, we always use the polyfill because
6// it's a very new API right now.
7
8// Not exported from index.
9/** @private */
10export 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. */
33export 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