@azure/abort-controller 1.0.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # Azure Abort Controller library for JS
2
+
3
+ The `@azure/abort-controller` package provides `AbortController` and `AbortSignal` classes. These classes are compatible
4
+ with the [AbortController](https://developer.mozilla.org/docs/Web/API/AbortController) built into modern browsers
5
+ and the `AbortSignal` used by [fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API).
6
+ Use the `AbortController` class to create an instance of the `AbortSignal` class that can be used to cancel an operation
7
+ in an Azure SDK that accept a parameter of type `AbortSignalLike`.
8
+
9
+ ## Getting started
10
+
11
+ ### Installation
12
+
13
+ Install this libray using npm as follows
14
+
15
+ ```
16
+ npm install @azure/abort-controller
17
+ ```
18
+
19
+ ## Key Concepts
20
+
21
+ Use the `AbortController` to create an `AbortSignal` which can then be passed to Azure SDK operations to cancel
22
+ pending work. The `AbortSignal` can be accessed via the `signal` property on an instantiated `AbortController`.
23
+ An `AbortSignal` can also be returned directly from a static method, e.g. `AbortController.timeout(100)`.
24
+ that is cancelled after 100 milliseconds.
25
+
26
+ Calling `abort()` on the instantiated `AbortController` invokes the regiestered `abort`
27
+ event listeners on the associated `AbortSignal`.
28
+ Any subsequent calls to `abort()` on the same controller will have no effect.
29
+
30
+ The `AbortSignal.none` static property returns an `AbortSignal` that can not be aborted.
31
+
32
+ Multiple instances of an `AbortSignal` can be linked so that calling `abort()` on the parent signal,
33
+ aborts all linked signals.
34
+ This linkage is one-way, meaning that a parent signal can affect a linked signal, but not the other way around.
35
+ To link `AbortSignals` together, pass in the parent signals to the `AbortController` constructor.
36
+
37
+ ## Examples
38
+
39
+ The below examples assume that `doAsyncWork` is a function that takes a bag of properties, one of which is
40
+ of the abort signal.
41
+
42
+ ### Example 1 - basic usage
43
+
44
+ ```js
45
+ import { AbortController } from "@azure/abort-controller";
46
+
47
+ const controller = new AbortController();
48
+ doAsyncWork({ abortSignal: controller.signal });
49
+
50
+ // at some point later
51
+ controller.abort();
52
+ ```
53
+
54
+ ### Example 2 - Aborting with timeout
55
+
56
+ ```js
57
+ import { AbortController } from "@azure/abort-controller";
58
+
59
+ const signal = AbortController.timeout(1000);
60
+ doAsyncWork({ abortSignal: signal });
61
+ ```
62
+
63
+ ### Example 3 - Aborting sub-tasks
64
+
65
+ ```js
66
+ import { AbortController } from "@azure/abort-controller";
67
+
68
+ const allTasksController = new AbortController();
69
+
70
+ const subTask1 = new AbortController(allTasksController.signal);
71
+ const subtask2 = new AbortController(allTasksController.signal);
72
+
73
+ allTasksController.abort(); // aborts allTasksSignal, subTask1, subTask2
74
+ subTask1.abort(); // aborts only subTask1
75
+ ```
76
+
77
+ ### Example 4 - Aborting with parent signal or timeout
78
+
79
+ ```js
80
+ import { AbortController } from "@azure/abort-controller";
81
+
82
+ const allTasksController = new AbortController();
83
+
84
+ // create a subtask controller that can be aborted manually,
85
+ // or when either the parent task aborts or the timeout is reached.
86
+ const subTask = new AbortController(allTasksController.signal, AbortController.timeout(100));
87
+
88
+ allTasksController.abort(); // aborts allTasksSignal, subTask
89
+ subTask.abort(); // aborts only subTask
90
+ ```
91
+
92
+ ## Contributing
93
+
94
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor
95
+ License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your
96
+ contribution. For details, visit https://cla.microsoft.com.
97
+
98
+ When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and
99
+ decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot.
100
+ You will only need to do this once across all repos using our CLA.
101
+
102
+ This project has adopted the Microsoft Open Source Code of Conduct.
103
+ For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional
104
+ questions or comments.
@@ -0,0 +1,286 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = global || self, factory(global.Aborter = {}));
5
+ }(this, function (exports) { 'use strict';
6
+
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation. All rights reserved.
9
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
10
+ this file except in compliance with the License. You may obtain a copy of the
11
+ License at http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16
+ MERCHANTABLITY OR NON-INFRINGEMENT.
17
+
18
+ See the Apache Version 2.0 License for specific language governing permissions
19
+ and limitations under the License.
20
+ ***************************************************************************** */
21
+ /* global Reflect, Promise */
22
+
23
+ var extendStatics = function(d, b) {
24
+ extendStatics = Object.setPrototypeOf ||
25
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
27
+ return extendStatics(d, b);
28
+ };
29
+
30
+ function __extends(d, b) {
31
+ extendStatics(d, b);
32
+ function __() { this.constructor = d; }
33
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
+ }
35
+
36
+ var listenersMap = new WeakMap();
37
+ var abortedMap = new WeakMap();
38
+ /**
39
+ * An aborter instance implements AbortSignal interface, can abort HTTP requests.
40
+ *
41
+ * - Call AbortSignal.none to create a new AbortSignal instance that cannot be cancelled.
42
+ * Use `AbortSignal.none` when you are required to pass a cancellation token but the operation
43
+ * cannot or will not ever be cancelled.
44
+ *
45
+ * @example
46
+ * // Abort without timeout
47
+ * await doAsyncWork(AbortSignal.none);
48
+ *
49
+ * @export
50
+ * @class AbortSignal
51
+ * @implements {AbortSignalLike}
52
+ */
53
+ var AbortSignal = /** @class */ (function () {
54
+ function AbortSignal() {
55
+ listenersMap.set(this, []);
56
+ abortedMap.set(this, false);
57
+ }
58
+ Object.defineProperty(AbortSignal.prototype, "aborted", {
59
+ /**
60
+ * Status of whether aborted or not.
61
+ *
62
+ * @readonly
63
+ * @type {boolean}
64
+ * @memberof AbortSignal
65
+ */
66
+ get: function () {
67
+ if (!abortedMap.has(this)) {
68
+ throw new TypeError("Expected `this` to be an instance of AbortSignal.");
69
+ }
70
+ return abortedMap.get(this);
71
+ },
72
+ enumerable: true,
73
+ configurable: true
74
+ });
75
+ Object.defineProperty(AbortSignal, "none", {
76
+ /**
77
+ * Creates a new AbortSignal instance that will never be aborted.
78
+ *
79
+ * @readonly
80
+ * @static
81
+ * @type {AbortSignal}
82
+ * @memberof AbortSignal
83
+ */
84
+ get: function () {
85
+ return new AbortSignal();
86
+ },
87
+ enumerable: true,
88
+ configurable: true
89
+ });
90
+ /**
91
+ * Added new "abort" event listener, only support "abort" event.
92
+ *
93
+ * @param {"abort"} _type Only support "abort" event
94
+ * @param {(this: AbortSignalLike, ev: any) => any} listener
95
+ * @memberof AbortSignal
96
+ */
97
+ AbortSignal.prototype.addEventListener = function (
98
+ // tslint:disable-next-line:variable-name
99
+ _type, listener) {
100
+ if (!listenersMap.has(this)) {
101
+ throw new TypeError("Expected `this` to be an instance of AbortSignal.");
102
+ }
103
+ var listeners = listenersMap.get(this);
104
+ listeners.push(listener);
105
+ };
106
+ /**
107
+ * Remove "abort" event listener, only support "abort" event.
108
+ *
109
+ * @param {"abort"} _type Only support "abort" event
110
+ * @param {(this: AbortSignalLike, ev: any) => any} listener
111
+ * @memberof AbortSignal
112
+ */
113
+ AbortSignal.prototype.removeEventListener = function (
114
+ // tslint:disable-next-line:variable-name
115
+ _type, listener) {
116
+ if (!listenersMap.has(this)) {
117
+ throw new TypeError("Expected `this` to be an instance of AbortSignal.");
118
+ }
119
+ var listeners = listenersMap.get(this);
120
+ var index = listeners.indexOf(listener);
121
+ if (index > -1) {
122
+ listeners.splice(index, 1);
123
+ }
124
+ };
125
+ return AbortSignal;
126
+ }());
127
+ /**
128
+ * Helper to trigger an abort event immediately, the onabort and all abort event listeners will be triggered.
129
+ * Will try to trigger abort event for all linked AbortSignal nodes.
130
+ *
131
+ * - If there is a timeout, the timer will be cancelled.
132
+ * - If aborted is true, nothing will happen.
133
+ *
134
+ * @returns
135
+ * @internal
136
+ */
137
+ function abortSignal(signal) {
138
+ if (signal.aborted) {
139
+ return;
140
+ }
141
+ if (signal.onabort) {
142
+ signal.onabort.call(signal);
143
+ }
144
+ var listeners = listenersMap.get(signal);
145
+ listeners.forEach(function (listener) {
146
+ listener.call(signal);
147
+ });
148
+ abortedMap.set(signal, true);
149
+ }
150
+
151
+ /**
152
+ * This error is thrown when an asynchronous operation has been aborted.
153
+ * Check for this error by testing the `name` that the name property of the
154
+ * error matches `"AbortError"`.
155
+ *
156
+ * @example
157
+ * const controller = new AbortController();
158
+ * controller.abort();
159
+ * try {
160
+ * doAsyncWork(controller.signal)
161
+ * } catch (e) {
162
+ * if (e.name === 'AbortError') {
163
+ * // handle abort error here.
164
+ * }
165
+ * }
166
+ */
167
+ var AbortError = /** @class */ (function (_super) {
168
+ __extends(AbortError, _super);
169
+ function AbortError(message) {
170
+ var _this = _super.call(this, message) || this;
171
+ _this.name = "AbortError";
172
+ return _this;
173
+ }
174
+ return AbortError;
175
+ }(Error));
176
+ /**
177
+ * An AbortController provides an AbortSignal and the associated controls to signal
178
+ * that an asynchronous operation should be aborted.
179
+ *
180
+ * @example
181
+ * // Abort an operation when another event fires
182
+ * const controller = new AbortController();
183
+ * const signal = controller.signal;
184
+ * doAsyncWork(signal);
185
+ * button.addEventListener('click', () => controller.abort());
186
+ *
187
+ * @example
188
+ * // Share aborter cross multiple operations in 30s
189
+ * // Upload the same data to 2 different data centers at the same time,
190
+ * // abort another when any of them is finished
191
+ * const controller = AbortController.withTimeout(30 * 1000);
192
+ * doAsyncWork(controller.signal).then(controller.abort);
193
+ * doAsyncWork(controller.signal).then(controller.abort);
194
+ *
195
+ * @example
196
+ * // Cascaded aborting
197
+ * // All operations can't take more than 30 seconds
198
+ * const aborter = Aborter.timeout(30 * 1000);
199
+ *
200
+ * // Following 2 operations can't take more than 25 seconds
201
+ * await doAsyncWork(aborter.withTimeout(25 * 1000));
202
+ * await doAsyncWork(aborter.withTimeout(25 * 1000));
203
+ *
204
+ * @export
205
+ * @class AbortController
206
+ * @implements {AbortSignalLike}
207
+ */
208
+ var AbortController = /** @class */ (function () {
209
+ function AbortController(parentSignals) {
210
+ var _this = this;
211
+ this._signal = new AbortSignal();
212
+ if (!parentSignals) {
213
+ return;
214
+ }
215
+ // coerce parentSignals into an array
216
+ if (!Array.isArray(parentSignals)) {
217
+ parentSignals = arguments;
218
+ }
219
+ for (var _i = 0, parentSignals_1 = parentSignals; _i < parentSignals_1.length; _i++) {
220
+ var parentSignal = parentSignals_1[_i];
221
+ // if the parent signal has already had abort() called,
222
+ // then call abort on this signal as well.
223
+ if (parentSignal.aborted) {
224
+ this.abort();
225
+ }
226
+ else {
227
+ // when the parent signal aborts, this signal should as well.
228
+ parentSignal.addEventListener("abort", function () {
229
+ _this.abort();
230
+ });
231
+ }
232
+ }
233
+ }
234
+ Object.defineProperty(AbortController.prototype, "signal", {
235
+ /**
236
+ * The AbortSignal associated with this controller that will signal aborted
237
+ * when the abort method is called on this controller.
238
+ *
239
+ * @readonly
240
+ * @type {AbortSignal}
241
+ * @memberof AbortController
242
+ */
243
+ get: function () {
244
+ return this._signal;
245
+ },
246
+ enumerable: true,
247
+ configurable: true
248
+ });
249
+ /**
250
+ * Signal that any operations passed this controller's associated abort signal
251
+ * to cancel any remaining work and throw an `AbortError`.
252
+ *
253
+ * @memberof AbortController
254
+ */
255
+ AbortController.prototype.abort = function () {
256
+ abortSignal(this._signal);
257
+ };
258
+ /**
259
+ * Creates a new AbortSignal instance that will abort after the provided ms.
260
+ *
261
+ * @static
262
+ * @params {number} ms Elapsed time in milliseconds to trigger an abort.
263
+ * @returns {AbortSignal}
264
+ */
265
+ AbortController.timeout = function (ms) {
266
+ var signal = new AbortSignal();
267
+ var timer = setTimeout(abortSignal, ms, signal);
268
+ // Prevent the active Timer from keeping the Node.js event loop active.
269
+ if (typeof timer.unref === "function") {
270
+ timer.unref();
271
+ }
272
+ return signal;
273
+ };
274
+ return AbortController;
275
+ }());
276
+
277
+ /// <reference lib="es5" />
278
+
279
+ exports.AbortController = AbortController;
280
+ exports.AbortError = AbortError;
281
+ exports.AbortSignal = AbortSignal;
282
+
283
+ Object.defineProperty(exports, '__esModule', { value: true });
284
+
285
+ }));
286
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../common/temp/node_modules/.registry.npmjs.org/tslib/1.10.0/node_modules/tslib/tslib.es6.js","../src/AbortSignal.ts","../src/AbortController.ts","../src/aborter.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\r\nthis file except in compliance with the License. You may obtain a copy of the\r\nLicense at http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\r\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\r\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\r\nMERCHANTABLITY OR NON-INFRINGEMENT.\r\n\r\nSee the Apache Version 2.0 License for specific language governing permissions\r\nand limitations under the License.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport function __exportStar(m, exports) {\r\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\r\n}\r\n\r\nexport function __values(o) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator], i = 0;\r\n if (m) return m.call(o);\r\n return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n};\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];\r\n result.default = mod;\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n","/// <reference path=\"./shims-public.d.ts\" />\ntype AbortEventListener = (this: AbortSignalLike, ev?: any) => any;\n\nconst listenersMap = new WeakMap<AbortSignal, AbortEventListener[]>();\nconst abortedMap = new WeakMap<AbortSignal, boolean>();\n\n/**\n * Allows the request to be aborted upon firing of the \"abort\" event.\n * Compatible with the browser built-in AbortSignal and common polyfills.\n */\nexport interface AbortSignalLike {\n /**\n * Indicates if the signal has already been aborted.\n */\n readonly aborted: boolean;\n /**\n * Add new \"abort\" event listener, only support \"abort\" event.\n */\n addEventListener(\n type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any,\n options?: any\n ): void;\n /**\n * Remove \"abort\" event listener, only support \"abort\" event.\n */\n removeEventListener(\n type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any,\n options?: any\n ): void;\n}\n\n/**\n * An aborter instance implements AbortSignal interface, can abort HTTP requests.\n *\n * - Call AbortSignal.none to create a new AbortSignal instance that cannot be cancelled.\n * Use `AbortSignal.none` when you are required to pass a cancellation token but the operation\n * cannot or will not ever be cancelled.\n *\n * @example\n * // Abort without timeout\n * await doAsyncWork(AbortSignal.none);\n *\n * @export\n * @class AbortSignal\n * @implements {AbortSignalLike}\n */\nexport class AbortSignal implements AbortSignalLike {\n constructor() {\n listenersMap.set(this, []);\n abortedMap.set(this, false);\n }\n\n /**\n * Status of whether aborted or not.\n *\n * @readonly\n * @type {boolean}\n * @memberof AbortSignal\n */\n public get aborted(): boolean {\n if (!abortedMap.has(this)) {\n throw new TypeError(\"Expected `this` to be an instance of AbortSignal.\");\n }\n\n return abortedMap.get(this)!;\n }\n\n /**\n * Creates a new AbortSignal instance that will never be aborted.\n *\n * @readonly\n * @static\n * @type {AbortSignal}\n * @memberof AbortSignal\n */\n public static get none(): AbortSignal {\n return new AbortSignal();\n }\n\n /**\n * onabort event listener.\n *\n * @memberof AbortSignal\n */\n public onabort?: (ev?: Event) => any;\n\n /**\n * Added new \"abort\" event listener, only support \"abort\" event.\n *\n * @param {\"abort\"} _type Only support \"abort\" event\n * @param {(this: AbortSignalLike, ev: any) => any} listener\n * @memberof AbortSignal\n */\n public addEventListener(\n // tslint:disable-next-line:variable-name\n _type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any\n ): void {\n if (!listenersMap.has(this)) {\n throw new TypeError(\"Expected `this` to be an instance of AbortSignal.\");\n }\n\n const listeners = listenersMap.get(this)!;\n listeners.push(listener);\n }\n\n /**\n * Remove \"abort\" event listener, only support \"abort\" event.\n *\n * @param {\"abort\"} _type Only support \"abort\" event\n * @param {(this: AbortSignalLike, ev: any) => any} listener\n * @memberof AbortSignal\n */\n public removeEventListener(\n // tslint:disable-next-line:variable-name\n _type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any\n ): void {\n if (!listenersMap.has(this)) {\n throw new TypeError(\"Expected `this` to be an instance of AbortSignal.\");\n }\n\n const listeners = listenersMap.get(this)!;\n\n const index = listeners.indexOf(listener);\n if (index > -1) {\n listeners.splice(index, 1);\n }\n }\n}\n\n/**\n * Helper to trigger an abort event immediately, the onabort and all abort event listeners will be triggered.\n * Will try to trigger abort event for all linked AbortSignal nodes.\n *\n * - If there is a timeout, the timer will be cancelled.\n * - If aborted is true, nothing will happen.\n *\n * @returns\n * @internal\n */\nexport function abortSignal(signal: AbortSignal) {\n if (signal.aborted) {\n return;\n }\n\n if (signal.onabort) {\n signal.onabort.call(signal);\n }\n\n const listeners = listenersMap.get(signal)!;\n listeners.forEach((listener) => {\n listener.call(signal);\n });\n\n abortedMap.set(signal, true);\n}\n","import { AbortSignal, abortSignal, AbortSignalLike } from \"./AbortSignal\";\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork(controller.signal)\n * } catch (e) {\n * if (e.name === 'AbortError') {\n * // handle abort error here.\n * }\n * }\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n\n/**\n * An AbortController provides an AbortSignal and the associated controls to signal\n * that an asynchronous operation should be aborted.\n *\n * @example\n * // Abort an operation when another event fires\n * const controller = new AbortController();\n * const signal = controller.signal;\n * doAsyncWork(signal);\n * button.addEventListener('click', () => controller.abort());\n *\n * @example\n * // Share aborter cross multiple operations in 30s\n * // Upload the same data to 2 different data centers at the same time,\n * // abort another when any of them is finished\n * const controller = AbortController.withTimeout(30 * 1000);\n * doAsyncWork(controller.signal).then(controller.abort);\n * doAsyncWork(controller.signal).then(controller.abort);\n *\n * @example\n * // Cascaded aborting\n * // All operations can't take more than 30 seconds\n * const aborter = Aborter.timeout(30 * 1000);\n *\n * // Following 2 operations can't take more than 25 seconds\n * await doAsyncWork(aborter.withTimeout(25 * 1000));\n * await doAsyncWork(aborter.withTimeout(25 * 1000));\n *\n * @export\n * @class AbortController\n * @implements {AbortSignalLike}\n */\nexport class AbortController {\n private _signal: AbortSignal;\n\n /**\n * @param {AbortSignalLike[]} [parentSignals] The AbortSignals that will signal aborted on the AbortSignal associated with this controller.\n * @constructor\n */\n constructor(parentSignals?: AbortSignalLike[]);\n /**\n * @param {...AbortSignalLike} parentSignals The AbortSignals that will signal aborted on the AbortSignal associated with this controller.\n * @constructor\n */\n constructor(...parentSignals: AbortSignalLike[]);\n constructor(parentSignals?: any) {\n this._signal = new AbortSignal();\n\n if (!parentSignals) {\n return;\n }\n // coerce parentSignals into an array\n if (!Array.isArray(parentSignals)) {\n parentSignals = arguments;\n }\n for (const parentSignal of parentSignals) {\n // if the parent signal has already had abort() called,\n // then call abort on this signal as well.\n if (parentSignal.aborted) {\n this.abort();\n } else {\n // when the parent signal aborts, this signal should as well.\n parentSignal.addEventListener(\"abort\", () => {\n this.abort();\n });\n }\n }\n }\n\n /**\n * The AbortSignal associated with this controller that will signal aborted\n * when the abort method is called on this controller.\n *\n * @readonly\n * @type {AbortSignal}\n * @memberof AbortController\n */\n public get signal() {\n return this._signal;\n }\n\n /**\n * Signal that any operations passed this controller's associated abort signal\n * to cancel any remaining work and throw an `AbortError`.\n *\n * @memberof AbortController\n */\n abort() {\n abortSignal(this._signal);\n }\n\n /**\n * Creates a new AbortSignal instance that will abort after the provided ms.\n *\n * @static\n * @params {number} ms Elapsed time in milliseconds to trigger an abort.\n * @returns {AbortSignal}\n */\n public static timeout(ms: number): AbortSignal {\n const signal = new AbortSignal();\n const timer = setTimeout(abortSignal, ms, signal);\n // Prevent the active Timer from keeping the Node.js event loop active.\n if (typeof timer.unref === \"function\") {\n timer.unref();\n }\n return signal;\n }\n}\n","/// <reference lib=\"es5\" />\n\n// Changes to Aborter\n// * Rename Aborter to AbortSignal\n// * Remove withValue and getValue - async context should be solved differently/wholistically, not tied to cancellation\n// * Remove withTimeout, it's moved to the controller\n// * AbortSignal constructor no longer takes a parent. Cancellation graphs are created from the controller.\n\n// Potential changes to align with DOM Spec\n// * dispatchEvent on Signal\n\nexport { AbortController, AbortError } from \"./AbortController\";\nexport { AbortSignal,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