@azure/abort-controller 1.0.1 → 1.0.2

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.
@@ -1,15 +1,21 @@
1
- ## 1.0.1 - 2019-12-04
1
+ # Release History
2
+
3
+ ## 1.0.2 (2020-01-07)
4
+
5
+ Updates the `tslib` dependency to version 2.x.
6
+
7
+ ## 1.0.1 (2019-12-04)
2
8
 
3
9
  Fixes the [bug 6271](https://github.com/Azure/azure-sdk-for-js/issues/6271) that can occur with angular prod builds due to triple-slash directives.
4
10
  ([PR 6344](https://github.com/Azure/azure-sdk-for-js/pull/6344))
5
11
 
6
- ## 1.0.0 - 2019-10-29
12
+ ## 1.0.0 (2019-10-29)
7
13
 
8
14
  This release marks the general availability of the `@azure/abort-controller` package.
9
15
 
10
16
  Removed the browser bundle. A browser-compatible library can still be created through the use of a bundler such as Rollup, Webpack, or Parcel.
11
17
  ([#5860](https://github.com/Azure/azure-sdk-for-js/pull/5860))
12
18
 
13
- ## 1.0.0-preview.2 - 2019-09-09
19
+ ## 1.0.0-preview.2 (2019-09-09)
14
20
 
15
21
  Listeners attached to an `AbortSignal` now receive an event with the type `abort`. (PR #4756)
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
1
+ The MIT License (MIT)
2
2
 
3
- Copyright (c) Microsoft Corporation. All rights reserved.
3
+ Copyright (c) 2020 Microsoft
4
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:
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
11
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
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
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 CHANGED
@@ -1,4 +1,4 @@
1
- # Azure Abort Controller library for JS
1
+ # Azure Abort Controller library for JavaScript
2
2
 
3
3
  The `@azure/abort-controller` package provides `AbortController` and `AbortSignal` classes. These classes are compatible
4
4
  with the [AbortController](https://developer.mozilla.org/docs/Web/API/AbortController) built into modern browsers
@@ -10,7 +10,7 @@ in an Azure SDK that accept a parameter of type `AbortSignalLike`.
10
10
 
11
11
  ### Installation
12
12
 
13
- Install this libray using npm as follows
13
+ Install this library using npm as follows
14
14
 
15
15
  ```
16
16
  npm install @azure/abort-controller
@@ -91,19 +91,6 @@ subTask.abort(); // aborts only subTask
91
91
 
92
92
  ## Contributing
93
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
- If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/tree/b38ae36b293f08f72b80dbb1d75cb4d276098fa1/CONTRIBUTING.md) to learn more about how to build and test the code.
103
-
104
- This project has adopted the Microsoft Open Source Code of Conduct.
105
- For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional
106
- questions or comments.
107
-
94
+ If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code.
108
95
 
109
96
  ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fabort-controller%2FREADME.png)
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
6
 
7
+ // Copyright (c) Microsoft Corporation.
8
+ // Licensed under the MIT license.
7
9
  var listenersMap = new WeakMap();
8
10
  var abortedMap = new WeakMap();
9
11
  /**
@@ -14,19 +16,15 @@ var abortedMap = new WeakMap();
14
16
  * cannot or will not ever be cancelled.
15
17
  *
16
18
  * @example
17
- * // Abort without timeout
19
+ * Abort without timeout
20
+ * ```ts
18
21
  * await doAsyncWork(AbortSignal.none);
19
- *
20
- * @export
21
- * @class AbortSignal
22
- * @implements {AbortSignalLike}
22
+ * ```
23
23
  */
24
24
  var AbortSignal = /** @class */ (function () {
25
25
  function AbortSignal() {
26
26
  /**
27
27
  * onabort event listener.
28
- *
29
- * @memberof AbortSignal
30
28
  */
31
29
  this.onabort = null;
32
30
  listenersMap.set(this, []);
@@ -37,8 +35,6 @@ var AbortSignal = /** @class */ (function () {
37
35
  * Status of whether aborted or not.
38
36
  *
39
37
  * @readonly
40
- * @type {boolean}
41
- * @memberof AbortSignal
42
38
  */
43
39
  get: function () {
44
40
  if (!abortedMap.has(this)) {
@@ -46,7 +42,7 @@ var AbortSignal = /** @class */ (function () {
46
42
  }
47
43
  return abortedMap.get(this);
48
44
  },
49
- enumerable: true,
45
+ enumerable: false,
50
46
  configurable: true
51
47
  });
52
48
  Object.defineProperty(AbortSignal, "none", {
@@ -54,22 +50,18 @@ var AbortSignal = /** @class */ (function () {
54
50
  * Creates a new AbortSignal instance that will never be aborted.
55
51
  *
56
52
  * @readonly
57
- * @static
58
- * @type {AbortSignal}
59
- * @memberof AbortSignal
60
53
  */
61
54
  get: function () {
62
55
  return new AbortSignal();
63
56
  },
64
- enumerable: true,
57
+ enumerable: false,
65
58
  configurable: true
66
59
  });
67
60
  /**
68
61
  * Added new "abort" event listener, only support "abort" event.
69
62
  *
70
- * @param {"abort"} _type Only support "abort" event
71
- * @param {(this: AbortSignalLike, ev: any) => any} listener
72
- * @memberof AbortSignal
63
+ * @param _type - Only support "abort" event
64
+ * @param listener - The listener to be added
73
65
  */
74
66
  AbortSignal.prototype.addEventListener = function (
75
67
  // tslint:disable-next-line:variable-name
@@ -83,9 +75,8 @@ var AbortSignal = /** @class */ (function () {
83
75
  /**
84
76
  * Remove "abort" event listener, only support "abort" event.
85
77
  *
86
- * @param {"abort"} _type Only support "abort" event
87
- * @param {(this: AbortSignalLike, ev: any) => any} listener
88
- * @memberof AbortSignal
78
+ * @param _type - Only support "abort" event
79
+ * @param listener - The listener to be removed
89
80
  */
90
81
  AbortSignal.prototype.removeEventListener = function (
91
82
  // tslint:disable-next-line:variable-name
@@ -114,9 +105,9 @@ var AbortSignal = /** @class */ (function () {
114
105
  * - If there is a timeout, the timer will be cancelled.
115
106
  * - If aborted is true, nothing will happen.
116
107
  *
117
- * @returns
118
108
  * @internal
119
109
  */
110
+ // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
120
111
  function abortSignal(signal) {
121
112
  if (signal.aborted) {
122
113
  return;
@@ -133,12 +124,14 @@ function abortSignal(signal) {
133
124
  abortedMap.set(signal, true);
134
125
  }
135
126
 
127
+ // Copyright (c) Microsoft Corporation.
136
128
  /**
137
129
  * This error is thrown when an asynchronous operation has been aborted.
138
130
  * Check for this error by testing the `name` that the name property of the
139
131
  * error matches `"AbortError"`.
140
132
  *
141
133
  * @example
134
+ * ```ts
142
135
  * const controller = new AbortController();
143
136
  * controller.abort();
144
137
  * try {
@@ -148,6 +141,7 @@ function abortSignal(signal) {
148
141
  * // handle abort error here.
149
142
  * }
150
143
  * }
144
+ * ```
151
145
  */
152
146
  var AbortError = /** @class */ (function (_super) {
153
147
  tslib.__extends(AbortError, _super);
@@ -163,34 +157,37 @@ var AbortError = /** @class */ (function (_super) {
163
157
  * that an asynchronous operation should be aborted.
164
158
  *
165
159
  * @example
166
- * // Abort an operation when another event fires
160
+ * Abort an operation when another event fires
161
+ * ```ts
167
162
  * const controller = new AbortController();
168
163
  * const signal = controller.signal;
169
164
  * doAsyncWork(signal);
170
165
  * button.addEventListener('click', () => controller.abort());
166
+ * ```
171
167
  *
172
168
  * @example
173
- * // Share aborter cross multiple operations in 30s
169
+ * Share aborter cross multiple operations in 30s
170
+ * ```ts
174
171
  * // Upload the same data to 2 different data centers at the same time,
175
172
  * // abort another when any of them is finished
176
173
  * const controller = AbortController.withTimeout(30 * 1000);
177
174
  * doAsyncWork(controller.signal).then(controller.abort);
178
175
  * doAsyncWork(controller.signal).then(controller.abort);
176
+ *```
179
177
  *
180
178
  * @example
181
- * // Cascaded aborting
179
+ * Cascaded aborting
180
+ * ```ts
182
181
  * // All operations can't take more than 30 seconds
183
182
  * const aborter = Aborter.timeout(30 * 1000);
184
183
  *
185
184
  * // Following 2 operations can't take more than 25 seconds
186
185
  * await doAsyncWork(aborter.withTimeout(25 * 1000));
187
186
  * await doAsyncWork(aborter.withTimeout(25 * 1000));
188
- *
189
- * @export
190
- * @class AbortController
191
- * @implements {AbortSignalLike}
187
+ * ```
192
188
  */
193
189
  var AbortController = /** @class */ (function () {
190
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
194
191
  function AbortController(parentSignals) {
195
192
  var _this = this;
196
193
  this._signal = new AbortSignal();
@@ -199,6 +196,7 @@ var AbortController = /** @class */ (function () {
199
196
  }
200
197
  // coerce parentSignals into an array
201
198
  if (!Array.isArray(parentSignals)) {
199
+ // eslint-disable-next-line prefer-rest-params
202
200
  parentSignals = arguments;
203
201
  }
204
202
  for (var _i = 0, parentSignals_1 = parentSignals; _i < parentSignals_1.length; _i++) {
@@ -222,30 +220,23 @@ var AbortController = /** @class */ (function () {
222
220
  * when the abort method is called on this controller.
223
221
  *
224
222
  * @readonly
225
- * @type {AbortSignal}
226
- * @memberof AbortController
227
223
  */
228
224
  get: function () {
229
225
  return this._signal;
230
226
  },
231
- enumerable: true,
227
+ enumerable: false,
232
228
  configurable: true
233
229
  });
234
230
  /**
235
231
  * Signal that any operations passed this controller's associated abort signal
236
232
  * to cancel any remaining work and throw an `AbortError`.
237
- *
238
- * @memberof AbortController
239
233
  */
240
234
  AbortController.prototype.abort = function () {
241
235
  abortSignal(this._signal);
242
236
  };
243
237
  /**
244
238
  * Creates a new AbortSignal instance that will abort after the provided ms.
245
- *
246
- * @static
247
- * @params {number} ms Elapsed time in milliseconds to trigger an abort.
248
- * @returns {AbortSignal}
239
+ * @param ms - Elapsed time in milliseconds to trigger an abort.
249
240
  */
250
241
  AbortController.timeout = function (ms) {
251
242
  var signal = new AbortSignal();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/AbortSignal.ts","../src/AbortController.ts"],"sourcesContent":["/// <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) | null = null;\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 * Dispatches a synthetic event to the AbortSignal.\n */\n dispatchEvent(_event: Event): boolean {\n throw new Error(\n \"This is a stub dispatchEvent implementation that should not be used. It only exists for type-checking purposes.\"\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 if (listeners) {\n listeners.forEach((listener) => {\n listener.call(signal, { type: \"abort\" });\n });\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"],"names":["__extends"],"mappings":";;;;;;AAGA,IAAM,YAAY,GAAG,IAAI,OAAO,EAAqC,CAAC;AACtE,IAAM,UAAU,GAAG,IAAI,OAAO,EAAwB,CAAC;;;;;;;;;;;;;;;;AA4CvD;IACE;;;;;;QAqCO,YAAO,GAAiC,IAAI,CAAC;QApClD,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC3B,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KAC7B;IASD,sBAAW,gCAAO;;;;;;;;aAAlB;YACE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBACzB,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC,CAAC;aAC1E;YAED,OAAO,UAAU,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;SAC9B;;;OAAA;IAUD,sBAAkB,mBAAI;;;;;;;;;aAAtB;YACE,OAAO,IAAI,WAAW,EAAE,CAAC;SAC1B;;;OAAA;;;;;;;;IAgBM,sCAAgB,GAAvB;;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AK,UAAU,EAAE;YACrC,KAAK,CAAC,KAAK,EAAE,CAAC;SACf;QACD,OAAO,MAAM,CAAC;KACf;IACH,sBAAC;CAAA;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/AbortSignal.ts","../src/AbortController.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// eslint-disable-next-line @typescript-eslint/triple-slash-reference\n/// <reference path=\"../shims-public.d.ts\" />\n\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 * ```ts\n * await doAsyncWork(AbortSignal.none);\n * ```\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 */\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 */\n public static get none(): AbortSignal {\n return new AbortSignal();\n }\n\n /**\n * onabort event listener.\n */\n public onabort: ((ev?: Event) => any) | null = null;\n\n /**\n * Added new \"abort\" event listener, only support \"abort\" event.\n *\n * @param _type - Only support \"abort\" event\n * @param listener - The listener to be added\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 _type - Only support \"abort\" event\n * @param listener - The listener to be removed\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 * Dispatches a synthetic event to the AbortSignal.\n */\n dispatchEvent(_event: Event): boolean {\n throw new Error(\n \"This is a stub dispatchEvent implementation that should not be used. It only exists for type-checking purposes.\"\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 * @internal\n */\n// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\nexport function abortSignal(signal: AbortSignal): void {\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 if (listeners) {\n listeners.forEach((listener) => {\n listener.call(signal, { type: \"abort\" });\n });\n }\n\n abortedMap.set(signal, true);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { 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 * ```ts\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 * ```\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 * ```ts\n * const controller = new AbortController();\n * const signal = controller.signal;\n * doAsyncWork(signal);\n * button.addEventListener('click', () => controller.abort());\n * ```\n *\n * @example\n * Share aborter cross multiple operations in 30s\n * ```ts\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 *\n * @example\n * Cascaded aborting\n * ```ts\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 */\nexport class AbortController {\n private _signal: AbortSignal;\n\n /**\n * @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller.\n */\n constructor(parentSignals?: AbortSignalLike[]);\n /**\n * @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller.\n */\n constructor(...parentSignals: AbortSignalLike[]);\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\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 // eslint-disable-next-line prefer-rest-params\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 */\n public get signal(): AbortSignal {\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 abort(): void {\n abortSignal(this._signal);\n }\n\n /**\n * Creates a new AbortSignal instance that will abort after the provided ms.\n * @param ms - Elapsed time in milliseconds to trigger an abort.\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"],"names":["__extends"],"mappings":";;;;;;AAAA;AACA;AAOA,IAAM,YAAY,GAAG,IAAI,OAAO,EAAqC,CAAC;AACtE,IAAM,UAAU,GAAG,IAAI,OAAO,EAAwB,CAAC;AA6BvD;;;;;;;;;;;;;;IAcE;;;;QA8BO,YAAO,GAAiC,IAAI,CAAC;QA7BlD,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC3B,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KAC7B;IAOD,sBAAW,gCAAO;;;;;;aAAlB;YACE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBACzB,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC,CAAC;aAC1E;YAED,OAAO,UAAU,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;SAC9B;;;OAAA;IAOD,sBAAkB,mBAAI;;;;;;aAAtB;YAC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GAAG,UAAU,CAAC,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;;QAElD,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,EAAE;YACrC,KAAK,CAAC,KAAK,EAAE,CAAC;SACf;QACD,OAAO,MAAM,CAAC;KACf;IACH,sBAAC;AAAD,CAAC;;;;;;"}
@@ -1,3 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
1
3
  import { __extends } from "tslib";
2
4
  import { AbortSignal, abortSignal } from "./AbortSignal";
3
5
  /**
@@ -6,6 +8,7 @@ import { AbortSignal, abortSignal } from "./AbortSignal";
6
8
  * error matches `"AbortError"`.
7
9
  *
8
10
  * @example
11
+ * ```ts
9
12
  * const controller = new AbortController();
10
13
  * controller.abort();
11
14
  * try {
@@ -15,6 +18,7 @@ import { AbortSignal, abortSignal } from "./AbortSignal";
15
18
  * // handle abort error here.
16
19
  * }
17
20
  * }
21
+ * ```
18
22
  */
19
23
  var AbortError = /** @class */ (function (_super) {
20
24
  __extends(AbortError, _super);
@@ -31,34 +35,37 @@ export { AbortError };
31
35
  * that an asynchronous operation should be aborted.
32
36
  *
33
37
  * @example
34
- * // Abort an operation when another event fires
38
+ * Abort an operation when another event fires
39
+ * ```ts
35
40
  * const controller = new AbortController();
36
41
  * const signal = controller.signal;
37
42
  * doAsyncWork(signal);
38
43
  * button.addEventListener('click', () => controller.abort());
44
+ * ```
39
45
  *
40
46
  * @example
41
- * // Share aborter cross multiple operations in 30s
47
+ * Share aborter cross multiple operations in 30s
48
+ * ```ts
42
49
  * // Upload the same data to 2 different data centers at the same time,
43
50
  * // abort another when any of them is finished
44
51
  * const controller = AbortController.withTimeout(30 * 1000);
45
52
  * doAsyncWork(controller.signal).then(controller.abort);
46
53
  * doAsyncWork(controller.signal).then(controller.abort);
54
+ *```
47
55
  *
48
56
  * @example
49
- * // Cascaded aborting
57
+ * Cascaded aborting
58
+ * ```ts
50
59
  * // All operations can't take more than 30 seconds
51
60
  * const aborter = Aborter.timeout(30 * 1000);
52
61
  *
53
62
  * // Following 2 operations can't take more than 25 seconds
54
63
  * await doAsyncWork(aborter.withTimeout(25 * 1000));
55
64
  * await doAsyncWork(aborter.withTimeout(25 * 1000));
56
- *
57
- * @export
58
- * @class AbortController
59
- * @implements {AbortSignalLike}
65
+ * ```
60
66
  */
61
67
  var AbortController = /** @class */ (function () {
68
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
62
69
  function AbortController(parentSignals) {
63
70
  var _this = this;
64
71
  this._signal = new AbortSignal();
@@ -67,6 +74,7 @@ var AbortController = /** @class */ (function () {
67
74
  }
68
75
  // coerce parentSignals into an array
69
76
  if (!Array.isArray(parentSignals)) {
77
+ // eslint-disable-next-line prefer-rest-params
70
78
  parentSignals = arguments;
71
79
  }
72
80
  for (var _i = 0, parentSignals_1 = parentSignals; _i < parentSignals_1.length; _i++) {
@@ -90,30 +98,23 @@ var AbortController = /** @class */ (function () {
90
98
  * when the abort method is called on this controller.
91
99
  *
92
100
  * @readonly
93
- * @type {AbortSignal}
94
- * @memberof AbortController
95
101
  */
96
102
  get: function () {
97
103
  return this._signal;
98
104
  },
99
- enumerable: true,
105
+ enumerable: false,
100
106
  configurable: true
101
107
  });
102
108
  /**
103
109
  * Signal that any operations passed this controller's associated abort signal
104
110
  * to cancel any remaining work and throw an `AbortError`.
105
- *
106
- * @memberof AbortController
107
111
  */
108
112
  AbortController.prototype.abort = function () {
109
113
  abortSignal(this._signal);
110
114
  };
111
115
  /**
112
116
  * Creates a new AbortSignal instance that will abort after the provided ms.
113
- *
114
- * @static
115
- * @params {number} ms Elapsed time in milliseconds to trigger an abort.
116
- * @returns {AbortSignal}
117
+ * @param ms - Elapsed time in milliseconds to trigger an abort.
117
118
  */
118
119
  AbortController.timeout = function (ms) {
119
120
  var signal = new AbortSignal();
@@ -1 +1 @@
1
- {"version":3,"file":"AbortController.js","sourceRoot":"","sources":["../../src/AbortController.ts"],"names":[],"mappings":";A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KAAI,CAAC,KAAK,EAAE,CAAC;gBACf,CAAC,CAAC,CAAC;aACJ;SACF;IACH,CAAC;IAQD,sBAAW,mCAAM;QANjB;;;;;WAKG;aACH;YACE,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;;;OAAA;IAED;;;OAGG;IACH,+BAAK,GAAL;QACE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACW,uBAAO,GAArB,UAAsB,EAAU;QAC9B,IAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QACjC,IAAM,KAAK,GAAG,UAAU,CAAC,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QAClD,uEAAuE;QACvE,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,EAAE;YACrC,KAAK,CAAC,KAAK,EAAE,CAAC;SACf;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,sBAAC;AAAD,CAAC,AApED,IAoEC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { 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 * ```ts\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 * ```\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 * ```ts\n * const controller = new AbortController();\n * const signal = controller.signal;\n * doAsyncWork(signal);\n * button.addEventListener('click', () => controller.abort());\n * ```\n *\n * @example\n * Share aborter cross multiple operations in 30s\n * ```ts\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 *\n * @example\n * Cascaded aborting\n * ```ts\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 */\nexport class AbortController {\n private _signal: AbortSignal;\n\n /**\n * @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller.\n */\n constructor(parentSignals?: AbortSignalLike[]);\n /**\n * @param parentSignals - The AbortSignals that will signal aborted on the AbortSignal associated with this controller.\n */\n constructor(...parentSignals: AbortSignalLike[]);\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\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 // eslint-disable-next-line prefer-rest-params\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 */\n public get signal(): AbortSignal {\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 abort(): void {\n abortSignal(this._signal);\n }\n\n /**\n * Creates a new AbortSignal instance that will abort after the provided ms.\n * @param ms - Elapsed time in milliseconds to trigger an abort.\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"]}
@@ -1,3 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
1
3
  var listenersMap = new WeakMap();
2
4
  var abortedMap = new WeakMap();
3
5
  /**
@@ -8,19 +10,15 @@ var abortedMap = new WeakMap();
8
10
  * cannot or will not ever be cancelled.
9
11
  *
10
12
  * @example
11
- * // Abort without timeout
13
+ * Abort without timeout
14
+ * ```ts
12
15
  * await doAsyncWork(AbortSignal.none);
13
- *
14
- * @export
15
- * @class AbortSignal
16
- * @implements {AbortSignalLike}
16
+ * ```
17
17
  */
18
18
  var AbortSignal = /** @class */ (function () {
19
19
  function AbortSignal() {
20
20
  /**
21
21
  * onabort event listener.
22
- *
23
- * @memberof AbortSignal
24
22
  */
25
23
  this.onabort = null;
26
24
  listenersMap.set(this, []);
@@ -31,8 +29,6 @@ var AbortSignal = /** @class */ (function () {
31
29
  * Status of whether aborted or not.
32
30
  *
33
31
  * @readonly
34
- * @type {boolean}
35
- * @memberof AbortSignal
36
32
  */
37
33
  get: function () {
38
34
  if (!abortedMap.has(this)) {
@@ -40,7 +36,7 @@ var AbortSignal = /** @class */ (function () {
40
36
  }
41
37
  return abortedMap.get(this);
42
38
  },
43
- enumerable: true,
39
+ enumerable: false,
44
40
  configurable: true
45
41
  });
46
42
  Object.defineProperty(AbortSignal, "none", {
@@ -48,22 +44,18 @@ var AbortSignal = /** @class */ (function () {
48
44
  * Creates a new AbortSignal instance that will never be aborted.
49
45
  *
50
46
  * @readonly
51
- * @static
52
- * @type {AbortSignal}
53
- * @memberof AbortSignal
54
47
  */
55
48
  get: function () {
56
49
  return new AbortSignal();
57
50
  },
58
- enumerable: true,
51
+ enumerable: false,
59
52
  configurable: true
60
53
  });
61
54
  /**
62
55
  * Added new "abort" event listener, only support "abort" event.
63
56
  *
64
- * @param {"abort"} _type Only support "abort" event
65
- * @param {(this: AbortSignalLike, ev: any) => any} listener
66
- * @memberof AbortSignal
57
+ * @param _type - Only support "abort" event
58
+ * @param listener - The listener to be added
67
59
  */
68
60
  AbortSignal.prototype.addEventListener = function (
69
61
  // tslint:disable-next-line:variable-name
@@ -77,9 +69,8 @@ var AbortSignal = /** @class */ (function () {
77
69
  /**
78
70
  * Remove "abort" event listener, only support "abort" event.
79
71
  *
80
- * @param {"abort"} _type Only support "abort" event
81
- * @param {(this: AbortSignalLike, ev: any) => any} listener
82
- * @memberof AbortSignal
72
+ * @param _type - Only support "abort" event
73
+ * @param listener - The listener to be removed
83
74
  */
84
75
  AbortSignal.prototype.removeEventListener = function (
85
76
  // tslint:disable-next-line:variable-name
@@ -109,9 +100,9 @@ export { AbortSignal };
109
100
  * - If there is a timeout, the timer will be cancelled.
110
101
  * - If aborted is true, nothing will happen.
111
102
  *
112
- * @returns
113
103
  * @internal
114
104
  */
105
+ // eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters
115
106
  export function abortSignal(signal) {
116
107
  if (signal.aborted) {
117
108
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"AbortSignal.js","sourceRoot":"","sources":["../../src/AbortSignal.ts"],"names":[],"mappings":"AAGA,IAAM,YAAY,GAAG,IAAI,OAAO,EAAqC,CAAC;AACtE,IAAM,UAAU,GAAG,IAAI,OAAO,EAAwB,CAAC;AA6BvD;;;;;;;;;;;;;;GAcG;AACH;IACE;QAgCA;;;;WAIG;QACI,YAAO,GAAiC,IAAI,CAAC;QApClD,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC3B,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IASD,sBAAW,gCAAO;QAPlB;;;;;;WAMG;aACH;YACE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBACzB,MAAM,IAAI,SAAS,CAAC,mDAAmD,CAAC,CAAC;aAC1E;YAED,OAAO,UAAU,CAAC,GAAG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AAE,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;KACJ;IAED,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// eslint-disable-next-line @typescript-eslint/triple-slash-reference\n/// <reference path=\"../shims-public.d.ts\" />\n\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 * ```ts\n * await doAsyncWork(AbortSignal.none);\n * ```\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 */\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 */\n public static get none(): AbortSignal {\n return new AbortSignal();\n }\n\n /**\n * onabort event listener.\n */\n public onabort: ((ev?: Event) => any) | null = null;\n\n /**\n * Added new \"abort\" event listener, only support \"abort\" event.\n *\n * @param _type - Only support \"abort\" event\n * @param listener - The listener to be added\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 _type - Only support \"abort\" event\n * @param listener - The listener to be removed\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 * Dispatches a synthetic event to the AbortSignal.\n */\n dispatchEvent(_event: Event): boolean {\n throw new Error(\n \"This is a stub dispatchEvent implementation that should not be used. It only exists for type-checking purposes.\"\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 * @internal\n */\n// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\nexport function abortSignal(signal: AbortSignal): void {\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 if (listeners) {\n listeners.forEach((listener) => {\n listener.call(signal, { type: \"abort\" });\n });\n }\n\n abortedMap.set(signal, true);\n}\n"]}
@@ -1,3 +1,5 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
1
3
  // Changes to Aborter
2
4
  // * Rename Aborter to AbortSignal
3
5
  // * Remove withValue and getValue - async context should be solved differently/wholistically, not tied to cancellation
@@ -7,4 +9,4 @@
7
9
  // * dispatchEvent on Signal
8
10
  export { AbortController, AbortError } from "./AbortController";
9
11
  export { AbortSignal } from "./AbortSignal";
10
- //# sourceMappingURL=aborter.js.map
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,qBAAqB;AACrB,kCAAkC;AAClC,uHAAuH;AACvH,qDAAqD;AACrD,2GAA2G;AAE3G,2CAA2C;AAC3C,4BAA4B;AAE5B,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAmB,MAAM,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\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, AbortSignalLike } from \"./AbortSignal\";\n"]}