@azure/abort-controller 1.0.1-dev.20200727.1 → 1.0.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 CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2020 Microsoft
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
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 JavaScript
1
+ # Azure Abort Controller library for JS
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 library using npm as follows
13
+ Install this libray using npm as follows
14
14
 
15
15
  ```
16
16
  npm install @azure/abort-controller
@@ -91,6 +91,19 @@ subTask.abort(); // aborts only subTask
91
91
 
92
92
  ## Contributing
93
93
 
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.
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
+
95
108
 
96
109
  ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fabort-controller%2FREADME.png)
@@ -1,17 +1,15 @@
1
- # Release History
2
-
3
- ## 1.0.1 (2019-12-04)
1
+ ## 1.0.1 - 2019-12-04
4
2
 
5
3
  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.
6
4
  ([PR 6344](https://github.com/Azure/azure-sdk-for-js/pull/6344))
7
5
 
8
- ## 1.0.0 (2019-10-29)
6
+ ## 1.0.0 - 2019-10-29
9
7
 
10
8
  This release marks the general availability of the `@azure/abort-controller` package.
11
9
 
12
10
  Removed the browser bundle. A browser-compatible library can still be created through the use of a bundler such as Rollup, Webpack, or Parcel.
13
11
  ([#5860](https://github.com/Azure/azure-sdk-for-js/pull/5860))
14
12
 
15
- ## 1.0.0-preview.2 (2019-09-09)
13
+ ## 1.0.0-preview.2 - 2019-09-09
16
14
 
17
15
  Listeners attached to an `AbortSignal` now receive an event with the type `abort`. (PR #4756)
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ var AbortSignal = /** @class */ (function () {
46
46
  }
47
47
  return abortedMap.get(this);
48
48
  },
49
- enumerable: false,
49
+ enumerable: true,
50
50
  configurable: true
51
51
  });
52
52
  Object.defineProperty(AbortSignal, "none", {
@@ -61,7 +61,7 @@ var AbortSignal = /** @class */ (function () {
61
61
  get: function () {
62
62
  return new AbortSignal();
63
63
  },
64
- enumerable: false,
64
+ enumerable: true,
65
65
  configurable: true
66
66
  });
67
67
  /**
@@ -228,7 +228,7 @@ var AbortController = /** @class */ (function () {
228
228
  get: function () {
229
229
  return this._signal;
230
230
  },
231
- enumerable: false,
231
+ enumerable: true,
232
232
  configurable: true
233
233
  });
234
234
  /**
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;AA6BvD;;;;;;;;;;;;;;;;IAgBE;;;;;;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,E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,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
+ {"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,C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;;;;;;;;IASa,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;;QAElD,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,EAAE;YACrC,KAAK,CAAC,KAAK,EAAE,CAAC;SACf;QACD,OAAO,MAAM,CAAC;KACf;IACH,sBAAC;CAAA;;;;;;"}
@@ -96,7 +96,7 @@ var AbortController = /** @class */ (function () {
96
96
  get: function () {
97
97
  return this._signal;
98
98
  },
99
- enumerable: false,
99
+ enumerable: true,
100
100
  configurable: true
101
101
  });
102
102
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AbortController.js","sourceRoot":"","sources":["../../src/AbortController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAmB,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;;;;;;GAeG;AACH;IAAgC,8BAAK;IACnC,oBAAY,OAAgB;QAA5B,YACE,kBAAM,OAAO,CAAC,SAEf;QADC,KAAI,CAAC,IAAI,GAAG,YAAY,CAAC;;IAC3B,CAAC;IACH,iBAAC;AAAD,CAAC,AALD,CAAgC,KAAK,GAKpC;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;IAaE,yBAAY,aAAmB;QAA/B,iBAsBC;QArBC,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAEjC,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO;SACR;QACD,qCAAqC;QACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YACjC,aAAa,GAAG,SAAS,CAAC;SAC3B;QACD,KAA2B,UAAa,EAAb,+BAAa,EAAb,2BAAa,EAAb,IAAa,EAAE;YAArC,IAAM,YAAY,sBAAA;YACrB,uDAAuD;YACvD,0CAA0C;YAC1C,IAAI,YAAY,CAAC,OAAO,EAAE;gBACxB,IAAI,CAAC,KAAK,EAAE,CAAC;aACd;iBAAM;gBACL,6DAA6D;gBAC7D,YAAY,CAAC,gBAAgB,CAAC,OAAO,EAAE;oBACrC,KAAI,CAAC,KAAK,EAAE,CAAC;gBACf,CAAC,CAAC,CAAC;aACJ;SACF;IACH,CAAC;IAUD,sBAAW,mCAAM;QARjB;;;;;;;WAOG;aACH;YACE,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;;;OAAA;IAED;;;;;OAKG;IACH,+BAAK,GAAL;QACE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;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,AA3ED,IA2EC","sourcesContent":["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"]}
1
+ {"version":3,"file":"AbortController.js","sourceRoot":"","sources":["../../src/AbortController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAmB,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;;;;;;GAeG;AACH;IAAgC,8BAAK;IACnC,oBAAY,OAAgB;QAA5B,YACE,kBAAM,OAAO,CAAC,SAEf;QADC,KAAI,CAAC,IAAI,GAAG,YAAY,CAAC;;IAC3B,CAAC;IACH,iBAAC;AAAD,CAAC,AALD,CAAgC,KAAK,GAKpC;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH;IAaE,yBAAY,aAAmB;QAA/B,iBAsBC;QArBC,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAEjC,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO;SACR;QACD,qCAAqC;QACrC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YACjC,aAAa,GAAG,SAAS,CAAC;SAC3B;QACD,KAA2B,UAAa,EAAb,+BAAa,EAAb,2BAAa,EAAb,IAAa,EAAE;YAArC,IAAM,YAAY,sBAAA;YACrB,uDAAuD;YACvD,0CAA0C;YAC1C,IAAI,YAAY,CAAC,OAAO,EAAE;gBACxB,IAAI,CAAC,KAAK,EAAE,CAAC;aACd;iBAAM;gBACL,6DAA6D;gBAC7D,YAAY,CAAC,gBAAgB,CAAC,OAAO,EAAE;oBACrC,KAAI,CAAC,KAAK,EAAE,CAAC;gBACf,CAAC,CAAC,CAAC;aACJ;SACF;IACH,CAAC;IAUD,sBAAW,mCAAM;QARjB;;;;;;;WAOG;aACH;YACE,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,CAAC;;;OAAA;IAED;;;;;OAKG;IACH,+BAAK,GAAL;QACE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;;OAMG;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,AA3ED,IA2EC"}
@@ -40,7 +40,7 @@ var AbortSignal = /** @class */ (function () {
40
40
  }
41
41
  return abortedMap.get(this);
42
42
  },
43
- enumerable: false,
43
+ enumerable: true,
44
44
  configurable: true
45
45
  });
46
46
  Object.defineProperty(AbortSignal, "none", {
@@ -55,7 +55,7 @@ var AbortSignal = /** @class */ (function () {
55
55
  get: function () {
56
56
  return new AbortSignal();
57
57
  },
58
- enumerable: false,
58
+ enumerable: true,
59
59
  configurable: true
60
60
  });
61
61
  /**
@@ -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,C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AAD,CAAC,AA5FD,IA4FC;;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,MAAmB;IAC7C,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,OAAO;KACR;IAED,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KAC7B;IAED,IAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC;IAC5C,IAAI,SAAS,EAAE;QACb,SAAS,CAAC,OAAO,CAAC,UAAC,QAAQ;YACzB,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;KACJ;IAED,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC","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"]}
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,CAAC,IAAI,CAAE,CAAC;QAC/B,CAAC;;;OAAA;IAUD,sBAAkB,mBAAI;QARtB;;;;;;;WAOG;aACH;YACE,OAAO,IAAI,WAAW,EAAE,CAAC;QAC3B,CAAC;;;OAAA;IASD;;;;;;OAMG;IACI,sCAAgB,GAAvB;IACE,yCAAyC;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I,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;KACJ;IAED,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"aborter.js","sourceRoot":"","sources":["../../src/aborter.ts"],"names":[],"mappings":"AAAA,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":["// 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"]}
1
+ {"version":3,"file":"aborter.js","sourceRoot":"","sources":["../../src/aborter.ts"],"names":[],"mappings":"AAAA,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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@azure/abort-controller",
3
3
  "sdk-type": "client",
4
- "version": "1.0.1-dev.20200727.1",
4
+ "version": "1.0.1",
5
5
  "description": "Microsoft Azure SDK for JavaScript - Aborter",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist-esm/src/aborter.js",
@@ -11,16 +11,16 @@
11
11
  "build:nodebrowser": "rollup -c 2>&1",
12
12
  "build:test": "rollup -c rollup.test.config.js 2>&1",
13
13
  "build": "npm run build:es6 && npm run build:nodebrowser",
14
- "check-format": "prettier --list-different --config ../../.prettierrc.json --ignore-path ../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
15
- "clean": "rimraf dist dist-esm dist-test types temp dist-browser/*.js* dist-browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml",
14
+ "check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
15
+ "clean": "rimraf dist dist-esm dist-test types temp browser/*.js* browser/*.zip statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml",
16
16
  "execute:samples": "echo skipped",
17
17
  "extract-api": "tsc -p . && api-extractor run --local",
18
- "format": "prettier --write --config ../../.prettierrc.json --ignore-path ../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
18
+ "format": "prettier --write --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
19
19
  "integration-test:browser": "echo skipped",
20
20
  "integration-test:node": "echo skipped",
21
21
  "integration-test": "npm run integration-test:node && npm run integration-test:browser",
22
- "lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.ts\" -c ../../.eslintrc.old.json --fix --fix-type [problem,suggestion]",
23
- "lint": "eslint -c ../../.eslintrc.old.json src test --ext .ts -f html -o abort-controller-lintReport.html || exit 0",
22
+ "lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.ts\" -c ../../.eslintrc.json --fix --fix-type [problem,suggestion]",
23
+ "lint": "eslint -c ../../.eslintrc.json src test --ext .ts -f html -o abort-controller-lintReport.html || exit 0",
24
24
  "pack": "npm pack 2>&1",
25
25
  "prebuild": "npm run clean",
26
26
  "pretest": "npm run build:test",
@@ -28,7 +28,7 @@
28
28
  "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node",
29
29
  "test": "npm run build:test && npm run unit-test && npm run integration-test",
30
30
  "unit-test:browser": "karma start --single-run",
31
- "unit-test:node": "cross-env TS_NODE_FILES=true TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" mocha --require ts-node/register --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace --no-timeouts test/*.spec.ts",
31
+ "unit-test:node": "cross-env TS_NODE_FILES=true TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" mocha --require ts-node/register --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace --no-timeouts test/*.spec.ts",
32
32
  "unit-test": "npm run unit-test:node && npm run unit-test:browser"
33
33
  },
34
34
  "types": "./types/src/aborter.d.ts",
@@ -38,9 +38,9 @@
38
38
  "files": [
39
39
  "dist/",
40
40
  "dist-esm/src/",
41
+ "src/",
41
42
  "types/src",
42
- "README.md",
43
- "LICENSE"
43
+ "tsconfig.json"
44
44
  ],
45
45
  "repository": {
46
46
  "type": "git",
@@ -64,27 +64,24 @@
64
64
  "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/abort-controller",
65
65
  "sideEffects": false,
66
66
  "dependencies": {
67
- "tslib": "^2.0.0"
67
+ "tslib": "^1.9.3"
68
68
  },
69
69
  "devDependencies": {
70
- "@microsoft/api-extractor": "7.7.11",
71
- "@rollup/plugin-commonjs": "11.0.2",
72
- "@rollup/plugin-multi-entry": "^3.0.0",
73
- "@rollup/plugin-node-resolve": "^8.0.0",
70
+ "@microsoft/api-extractor": "^7.5.4",
74
71
  "@rollup/plugin-replace": "^2.2.0",
75
- "@types/mocha": "^7.0.2",
72
+ "@types/mocha": "^5.2.5",
76
73
  "@types/node": "^8.0.0",
77
74
  "@typescript-eslint/eslint-plugin": "^2.0.0",
78
75
  "@typescript-eslint/parser": "^2.0.0",
79
76
  "assert": "^1.4.1",
80
- "cross-env": "^7.0.2",
77
+ "cross-env": "^6.0.3",
81
78
  "delay": "^4.2.0",
82
79
  "eslint": "^6.1.0",
83
80
  "eslint-config-prettier": "^6.0.0",
84
81
  "eslint-plugin-no-null": "^1.0.2",
85
82
  "eslint-plugin-no-only-tests": "^2.3.0",
86
83
  "eslint-plugin-promise": "^4.1.1",
87
- "karma": "^5.1.0",
84
+ "karma": "^4.0.1",
88
85
  "karma-chrome-launcher": "^3.0.0",
89
86
  "karma-coverage": "^2.0.0",
90
87
  "karma-edge-launcher": "^0.4.2",
@@ -94,16 +91,20 @@
94
91
  "karma-junit-reporter": "^2.0.1",
95
92
  "karma-mocha": "^1.3.0",
96
93
  "karma-mocha-reporter": "^2.2.5",
97
- "karma-remap-istanbul": "^0.6.0",
98
- "mocha": "^7.1.1",
94
+ "karma-remap-coverage": "^0.1.5",
95
+ "mocha": "^6.2.2",
99
96
  "mocha-junit-reporter": "^1.18.0",
97
+ "mocha-multi": "^1.1.3",
100
98
  "nyc": "^14.0.0",
101
99
  "prettier": "^1.16.4",
102
100
  "rimraf": "^3.0.0",
103
101
  "rollup": "^1.16.3",
102
+ "rollup-plugin-commonjs": "^10.0.0",
103
+ "rollup-plugin-multi-entry": "^2.1.0",
104
+ "rollup-plugin-node-resolve": "^5.0.2",
104
105
  "rollup-plugin-sourcemaps": "^0.4.2",
105
106
  "rollup-plugin-terser": "^5.1.1",
106
107
  "ts-node": "^8.3.0",
107
- "typescript": "~3.9.3"
108
+ "typescript": "~3.6.4"
108
109
  }
109
110
  }
@@ -0,0 +1,133 @@
1
+ import { AbortSignal, abortSignal, AbortSignalLike } from "./AbortSignal";
2
+
3
+ /**
4
+ * This error is thrown when an asynchronous operation has been aborted.
5
+ * Check for this error by testing the `name` that the name property of the
6
+ * error matches `"AbortError"`.
7
+ *
8
+ * @example
9
+ * const controller = new AbortController();
10
+ * controller.abort();
11
+ * try {
12
+ * doAsyncWork(controller.signal)
13
+ * } catch (e) {
14
+ * if (e.name === 'AbortError') {
15
+ * // handle abort error here.
16
+ * }
17
+ * }
18
+ */
19
+ export class AbortError extends Error {
20
+ constructor(message?: string) {
21
+ super(message);
22
+ this.name = "AbortError";
23
+ }
24
+ }
25
+
26
+ /**
27
+ * An AbortController provides an AbortSignal and the associated controls to signal
28
+ * that an asynchronous operation should be aborted.
29
+ *
30
+ * @example
31
+ * // Abort an operation when another event fires
32
+ * const controller = new AbortController();
33
+ * const signal = controller.signal;
34
+ * doAsyncWork(signal);
35
+ * button.addEventListener('click', () => controller.abort());
36
+ *
37
+ * @example
38
+ * // Share aborter cross multiple operations in 30s
39
+ * // Upload the same data to 2 different data centers at the same time,
40
+ * // abort another when any of them is finished
41
+ * const controller = AbortController.withTimeout(30 * 1000);
42
+ * doAsyncWork(controller.signal).then(controller.abort);
43
+ * doAsyncWork(controller.signal).then(controller.abort);
44
+ *
45
+ * @example
46
+ * // Cascaded aborting
47
+ * // All operations can't take more than 30 seconds
48
+ * const aborter = Aborter.timeout(30 * 1000);
49
+ *
50
+ * // Following 2 operations can't take more than 25 seconds
51
+ * await doAsyncWork(aborter.withTimeout(25 * 1000));
52
+ * await doAsyncWork(aborter.withTimeout(25 * 1000));
53
+ *
54
+ * @export
55
+ * @class AbortController
56
+ * @implements {AbortSignalLike}
57
+ */
58
+ export class AbortController {
59
+ private _signal: AbortSignal;
60
+
61
+ /**
62
+ * @param {AbortSignalLike[]} [parentSignals] The AbortSignals that will signal aborted on the AbortSignal associated with this controller.
63
+ * @constructor
64
+ */
65
+ constructor(parentSignals?: AbortSignalLike[]);
66
+ /**
67
+ * @param {...AbortSignalLike} parentSignals The AbortSignals that will signal aborted on the AbortSignal associated with this controller.
68
+ * @constructor
69
+ */
70
+ constructor(...parentSignals: AbortSignalLike[]);
71
+ constructor(parentSignals?: any) {
72
+ this._signal = new AbortSignal();
73
+
74
+ if (!parentSignals) {
75
+ return;
76
+ }
77
+ // coerce parentSignals into an array
78
+ if (!Array.isArray(parentSignals)) {
79
+ parentSignals = arguments;
80
+ }
81
+ for (const parentSignal of parentSignals) {
82
+ // if the parent signal has already had abort() called,
83
+ // then call abort on this signal as well.
84
+ if (parentSignal.aborted) {
85
+ this.abort();
86
+ } else {
87
+ // when the parent signal aborts, this signal should as well.
88
+ parentSignal.addEventListener("abort", () => {
89
+ this.abort();
90
+ });
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * The AbortSignal associated with this controller that will signal aborted
97
+ * when the abort method is called on this controller.
98
+ *
99
+ * @readonly
100
+ * @type {AbortSignal}
101
+ * @memberof AbortController
102
+ */
103
+ public get signal() {
104
+ return this._signal;
105
+ }
106
+
107
+ /**
108
+ * Signal that any operations passed this controller's associated abort signal
109
+ * to cancel any remaining work and throw an `AbortError`.
110
+ *
111
+ * @memberof AbortController
112
+ */
113
+ abort() {
114
+ abortSignal(this._signal);
115
+ }
116
+
117
+ /**
118
+ * Creates a new AbortSignal instance that will abort after the provided ms.
119
+ *
120
+ * @static
121
+ * @params {number} ms Elapsed time in milliseconds to trigger an abort.
122
+ * @returns {AbortSignal}
123
+ */
124
+ public static timeout(ms: number): AbortSignal {
125
+ const signal = new AbortSignal();
126
+ const timer = setTimeout(abortSignal, ms, signal);
127
+ // Prevent the active Timer from keeping the Node.js event loop active.
128
+ if (typeof timer.unref === "function") {
129
+ timer.unref();
130
+ }
131
+ return signal;
132
+ }
133
+ }
@@ -0,0 +1,170 @@
1
+ /// <reference path="./shims-public.d.ts" />
2
+ type AbortEventListener = (this: AbortSignalLike, ev?: any) => any;
3
+
4
+ const listenersMap = new WeakMap<AbortSignal, AbortEventListener[]>();
5
+ const abortedMap = new WeakMap<AbortSignal, boolean>();
6
+
7
+ /**
8
+ * Allows the request to be aborted upon firing of the "abort" event.
9
+ * Compatible with the browser built-in AbortSignal and common polyfills.
10
+ */
11
+ export interface AbortSignalLike {
12
+ /**
13
+ * Indicates if the signal has already been aborted.
14
+ */
15
+ readonly aborted: boolean;
16
+ /**
17
+ * Add new "abort" event listener, only support "abort" event.
18
+ */
19
+ addEventListener(
20
+ type: "abort",
21
+ listener: (this: AbortSignalLike, ev: any) => any,
22
+ options?: any
23
+ ): void;
24
+ /**
25
+ * Remove "abort" event listener, only support "abort" event.
26
+ */
27
+ removeEventListener(
28
+ type: "abort",
29
+ listener: (this: AbortSignalLike, ev: any) => any,
30
+ options?: any
31
+ ): void;
32
+ }
33
+
34
+ /**
35
+ * An aborter instance implements AbortSignal interface, can abort HTTP requests.
36
+ *
37
+ * - Call AbortSignal.none to create a new AbortSignal instance that cannot be cancelled.
38
+ * Use `AbortSignal.none` when you are required to pass a cancellation token but the operation
39
+ * cannot or will not ever be cancelled.
40
+ *
41
+ * @example
42
+ * // Abort without timeout
43
+ * await doAsyncWork(AbortSignal.none);
44
+ *
45
+ * @export
46
+ * @class AbortSignal
47
+ * @implements {AbortSignalLike}
48
+ */
49
+ export class AbortSignal implements AbortSignalLike {
50
+ constructor() {
51
+ listenersMap.set(this, []);
52
+ abortedMap.set(this, false);
53
+ }
54
+
55
+ /**
56
+ * Status of whether aborted or not.
57
+ *
58
+ * @readonly
59
+ * @type {boolean}
60
+ * @memberof AbortSignal
61
+ */
62
+ public get aborted(): boolean {
63
+ if (!abortedMap.has(this)) {
64
+ throw new TypeError("Expected `this` to be an instance of AbortSignal.");
65
+ }
66
+
67
+ return abortedMap.get(this)!;
68
+ }
69
+
70
+ /**
71
+ * Creates a new AbortSignal instance that will never be aborted.
72
+ *
73
+ * @readonly
74
+ * @static
75
+ * @type {AbortSignal}
76
+ * @memberof AbortSignal
77
+ */
78
+ public static get none(): AbortSignal {
79
+ return new AbortSignal();
80
+ }
81
+
82
+ /**
83
+ * onabort event listener.
84
+ *
85
+ * @memberof AbortSignal
86
+ */
87
+ public onabort: ((ev?: Event) => any) | null = null;
88
+
89
+ /**
90
+ * Added new "abort" event listener, only support "abort" event.
91
+ *
92
+ * @param {"abort"} _type Only support "abort" event
93
+ * @param {(this: AbortSignalLike, ev: any) => any} listener
94
+ * @memberof AbortSignal
95
+ */
96
+ public addEventListener(
97
+ // tslint:disable-next-line:variable-name
98
+ _type: "abort",
99
+ listener: (this: AbortSignalLike, ev: any) => any
100
+ ): void {
101
+ if (!listenersMap.has(this)) {
102
+ throw new TypeError("Expected `this` to be an instance of AbortSignal.");
103
+ }
104
+
105
+ const listeners = listenersMap.get(this)!;
106
+ listeners.push(listener);
107
+ }
108
+
109
+ /**
110
+ * Remove "abort" event listener, only support "abort" event.
111
+ *
112
+ * @param {"abort"} _type Only support "abort" event
113
+ * @param {(this: AbortSignalLike, ev: any) => any} listener
114
+ * @memberof AbortSignal
115
+ */
116
+ public removeEventListener(
117
+ // tslint:disable-next-line:variable-name
118
+ _type: "abort",
119
+ listener: (this: AbortSignalLike, ev: any) => any
120
+ ): void {
121
+ if (!listenersMap.has(this)) {
122
+ throw new TypeError("Expected `this` to be an instance of AbortSignal.");
123
+ }
124
+
125
+ const listeners = listenersMap.get(this)!;
126
+
127
+ const index = listeners.indexOf(listener);
128
+ if (index > -1) {
129
+ listeners.splice(index, 1);
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Dispatches a synthetic event to the AbortSignal.
135
+ */
136
+ dispatchEvent(_event: Event): boolean {
137
+ throw new Error(
138
+ "This is a stub dispatchEvent implementation that should not be used. It only exists for type-checking purposes."
139
+ );
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Helper to trigger an abort event immediately, the onabort and all abort event listeners will be triggered.
145
+ * Will try to trigger abort event for all linked AbortSignal nodes.
146
+ *
147
+ * - If there is a timeout, the timer will be cancelled.
148
+ * - If aborted is true, nothing will happen.
149
+ *
150
+ * @returns
151
+ * @internal
152
+ */
153
+ export function abortSignal(signal: AbortSignal) {
154
+ if (signal.aborted) {
155
+ return;
156
+ }
157
+
158
+ if (signal.onabort) {
159
+ signal.onabort.call(signal);
160
+ }
161
+
162
+ const listeners = listenersMap.get(signal)!;
163
+ if (listeners) {
164
+ listeners.forEach((listener) => {
165
+ listener.call(signal, { type: "abort" });
166
+ });
167
+ }
168
+
169
+ abortedMap.set(signal, true);
170
+ }
package/src/aborter.ts ADDED
@@ -0,0 +1,11 @@
1
+ // Changes to Aborter
2
+ // * Rename Aborter to AbortSignal
3
+ // * Remove withValue and getValue - async context should be solved differently/wholistically, not tied to cancellation
4
+ // * Remove withTimeout, it's moved to the controller
5
+ // * AbortSignal constructor no longer takes a parent. Cancellation graphs are created from the controller.
6
+
7
+ // Potential changes to align with DOM Spec
8
+ // * dispatchEvent on Signal
9
+
10
+ export { AbortController, AbortError } from "./AbortController";
11
+ export { AbortSignal, AbortSignalLike } from "./AbortSignal";
@@ -0,0 +1,2 @@
1
+ // forward declaration of Event in case DOM libs are not present.
2
+ interface Event {}
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../../tsconfig.package",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "declarationDir": "./types",
6
+ "outDir": "./dist-esm"
7
+ },
8
+ "compileOnSave": true,
9
+ "exclude": ["node_modules", "./types/**/*.d.ts", "./samples/**/*.ts"],
10
+ "include": ["./src/**/*.ts", "./test/**/*.ts"]
11
+ }
@@ -70,7 +70,7 @@ export declare class AbortController {
70
70
  * @type {AbortSignal}
71
71
  * @memberof AbortController
72
72
  */
73
- get signal(): AbortSignal;
73
+ readonly signal: AbortSignal;
74
74
  /**
75
75
  * Signal that any operations passed this controller's associated abort signal
76
76
  * to cancel any remaining work and throw an `AbortError`.
@@ -1 +1 @@
1
- {"version":3,"file":"AbortController.d.ts","sourceRoot":"","sources":["../../src/AbortController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,eAAe,EAAE,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,CAAC,EAAE,MAAM;CAI7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAc;IAE7B;;;OAGG;gBACS,aAAa,CAAC,EAAE,eAAe,EAAE;IAC7C;;;OAGG;gBACS,GAAG,aAAa,EAAE,eAAe,EAAE;IAyB/C;;;;;;;OAOG;IACH,IAAW,MAAM,gBAEhB;IAED;;;;;OAKG;IACH,KAAK;IAIL;;;;;;OAMG;WACW,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW;CAS/C"}
1
+ {"version":3,"file":"AbortController.d.ts","sourceRoot":"","sources":["../../src/AbortController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,eAAe,EAAE,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,CAAC,EAAE,MAAM;CAI7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAc;IAE7B;;;OAGG;gBACS,aAAa,CAAC,EAAE,eAAe,EAAE;IAC7C;;;OAGG;gBACS,GAAG,aAAa,EAAE,eAAe,EAAE;IAyB/C;;;;;;;OAOG;aACQ,MAAM;IAIjB;;;;;OAKG;IACH,KAAK;IAIL;;;;;;OAMG;WACW,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW;CAS/C"}
@@ -41,7 +41,7 @@ export declare class AbortSignal implements AbortSignalLike {
41
41
  * @type {boolean}
42
42
  * @memberof AbortSignal
43
43
  */
44
- get aborted(): boolean;
44
+ readonly aborted: boolean;
45
45
  /**
46
46
  * Creates a new AbortSignal instance that will never be aborted.
47
47
  *
@@ -50,7 +50,7 @@ export declare class AbortSignal implements AbortSignalLike {
50
50
  * @type {AbortSignal}
51
51
  * @memberof AbortSignal
52
52
  */
53
- static get none(): AbortSignal;
53
+ static readonly none: AbortSignal;
54
54
  /**
55
55
  * onabort event listener.
56
56
  *
@@ -1 +1 @@
1
- {"version":3,"file":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