@azure/abort-controller
Advanced tools
Comparing version 1.0.5-alpha.20210615.1 to 1.0.5-alpha.20210617.1
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __extends } from "tslib"; | ||
import { AbortSignal, abortSignal } from "./AbortSignal"; | ||
@@ -23,12 +22,8 @@ /** | ||
*/ | ||
var AbortError = /** @class */ (function (_super) { | ||
__extends(AbortError, _super); | ||
function AbortError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = "AbortError"; | ||
return _this; | ||
export class AbortError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "AbortError"; | ||
} | ||
return AbortError; | ||
}(Error)); | ||
export { AbortError }; | ||
} | ||
/** | ||
@@ -68,6 +63,5 @@ * An AbortController provides an AbortSignal and the associated controls to signal | ||
*/ | ||
var AbortController = /** @class */ (function () { | ||
export class AbortController { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function AbortController(parentSignals) { | ||
var _this = this; | ||
constructor(parentSignals) { | ||
this._signal = new AbortSignal(); | ||
@@ -82,4 +76,3 @@ if (!parentSignals) { | ||
} | ||
for (var _i = 0, parentSignals_1 = parentSignals; _i < parentSignals_1.length; _i++) { | ||
var parentSignal = parentSignals_1[_i]; | ||
for (const parentSignal of parentSignals) { | ||
// if the parent signal has already had abort() called, | ||
@@ -92,4 +85,4 @@ // then call abort on this signal as well. | ||
// when the parent signal aborts, this signal should as well. | ||
parentSignal.addEventListener("abort", function () { | ||
_this.abort(); | ||
parentSignal.addEventListener("abort", () => { | ||
this.abort(); | ||
}); | ||
@@ -99,22 +92,18 @@ } | ||
} | ||
Object.defineProperty(AbortController.prototype, "signal", { | ||
/** | ||
* The AbortSignal associated with this controller that will signal aborted | ||
* when the abort method is called on this controller. | ||
* | ||
* @readonly | ||
*/ | ||
get: function () { | ||
return this._signal; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* The AbortSignal associated with this controller that will signal aborted | ||
* when the abort method is called on this controller. | ||
* | ||
* @readonly | ||
*/ | ||
get signal() { | ||
return this._signal; | ||
} | ||
/** | ||
* Signal that any operations passed this controller's associated abort signal | ||
* to cancel any remaining work and throw an `AbortError`. | ||
*/ | ||
AbortController.prototype.abort = function () { | ||
abort() { | ||
abortSignal(this._signal); | ||
}; | ||
} | ||
/** | ||
@@ -124,5 +113,5 @@ * Creates a new AbortSignal instance that will abort after the provided ms. | ||
*/ | ||
AbortController.timeout = function (ms) { | ||
var signal = new AbortSignal(); | ||
var timer = setTimeout(abortSignal, ms, signal); | ||
static timeout(ms) { | ||
const signal = new AbortSignal(); | ||
const timer = setTimeout(abortSignal, ms, signal); | ||
// Prevent the active Timer from keeping the Node.js event loop active. | ||
@@ -133,6 +122,4 @@ if (typeof timer.unref === "function") { | ||
return signal; | ||
}; | ||
return AbortController; | ||
}()); | ||
export { AbortController }; | ||
} | ||
} | ||
//# sourceMappingURL=AbortController.js.map |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
var listenersMap = new WeakMap(); | ||
var abortedMap = new WeakMap(); | ||
const listenersMap = new WeakMap(); | ||
const abortedMap = new WeakMap(); | ||
/** | ||
@@ -18,4 +18,4 @@ * An aborter instance implements AbortSignal interface, can abort HTTP requests. | ||
*/ | ||
var AbortSignal = /** @class */ (function () { | ||
function AbortSignal() { | ||
export class AbortSignal { | ||
constructor() { | ||
/** | ||
@@ -28,30 +28,22 @@ * onabort event listener. | ||
} | ||
Object.defineProperty(AbortSignal.prototype, "aborted", { | ||
/** | ||
* Status of whether aborted or not. | ||
* | ||
* @readonly | ||
*/ | ||
get: function () { | ||
if (!abortedMap.has(this)) { | ||
throw new TypeError("Expected `this` to be an instance of AbortSignal."); | ||
} | ||
return abortedMap.get(this); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(AbortSignal, "none", { | ||
/** | ||
* Creates a new AbortSignal instance that will never be aborted. | ||
* | ||
* @readonly | ||
*/ | ||
get: function () { | ||
return new AbortSignal(); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* Status of whether aborted or not. | ||
* | ||
* @readonly | ||
*/ | ||
get aborted() { | ||
if (!abortedMap.has(this)) { | ||
throw new TypeError("Expected `this` to be an instance of AbortSignal."); | ||
} | ||
return abortedMap.get(this); | ||
} | ||
/** | ||
* Creates a new AbortSignal instance that will never be aborted. | ||
* | ||
* @readonly | ||
*/ | ||
static get none() { | ||
return new AbortSignal(); | ||
} | ||
/** | ||
* Added new "abort" event listener, only support "abort" event. | ||
@@ -62,3 +54,3 @@ * | ||
*/ | ||
AbortSignal.prototype.addEventListener = function ( | ||
addEventListener( | ||
// tslint:disable-next-line:variable-name | ||
@@ -69,5 +61,5 @@ _type, listener) { | ||
} | ||
var listeners = listenersMap.get(this); | ||
const listeners = listenersMap.get(this); | ||
listeners.push(listener); | ||
}; | ||
} | ||
/** | ||
@@ -79,3 +71,3 @@ * Remove "abort" event listener, only support "abort" event. | ||
*/ | ||
AbortSignal.prototype.removeEventListener = function ( | ||
removeEventListener( | ||
// tslint:disable-next-line:variable-name | ||
@@ -86,17 +78,15 @@ _type, listener) { | ||
} | ||
var listeners = listenersMap.get(this); | ||
var index = listeners.indexOf(listener); | ||
const listeners = listenersMap.get(this); | ||
const index = listeners.indexOf(listener); | ||
if (index > -1) { | ||
listeners.splice(index, 1); | ||
} | ||
}; | ||
} | ||
/** | ||
* Dispatches a synthetic event to the AbortSignal. | ||
*/ | ||
AbortSignal.prototype.dispatchEvent = function (_event) { | ||
dispatchEvent(_event) { | ||
throw new Error("This is a stub dispatchEvent implementation that should not be used. It only exists for type-checking purposes."); | ||
}; | ||
return AbortSignal; | ||
}()); | ||
export { AbortSignal }; | ||
} | ||
} | ||
/** | ||
@@ -119,3 +109,3 @@ * Helper to trigger an abort event immediately, the onabort and all abort event listeners will be triggered. | ||
} | ||
var listeners = listenersMap.get(signal); | ||
const listeners = listenersMap.get(signal); | ||
if (listeners) { | ||
@@ -125,3 +115,3 @@ // Create a copy of listeners so mutations to the array | ||
// we invoke. | ||
listeners.slice().forEach(function (listener) { | ||
listeners.slice().forEach((listener) => { | ||
listener.call(signal, { type: "abort" }); | ||
@@ -128,0 +118,0 @@ }); |
@@ -5,8 +5,6 @@ 'use strict'; | ||
var tslib = require('tslib'); | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
var listenersMap = new WeakMap(); | ||
var abortedMap = new WeakMap(); | ||
const listenersMap = new WeakMap(); | ||
const abortedMap = new WeakMap(); | ||
/** | ||
@@ -25,4 +23,4 @@ * An aborter instance implements AbortSignal interface, can abort HTTP requests. | ||
*/ | ||
var AbortSignal = /** @class */ (function () { | ||
function AbortSignal() { | ||
class AbortSignal { | ||
constructor() { | ||
/** | ||
@@ -35,30 +33,22 @@ * onabort event listener. | ||
} | ||
Object.defineProperty(AbortSignal.prototype, "aborted", { | ||
/** | ||
* Status of whether aborted or not. | ||
* | ||
* @readonly | ||
*/ | ||
get: function () { | ||
if (!abortedMap.has(this)) { | ||
throw new TypeError("Expected `this` to be an instance of AbortSignal."); | ||
} | ||
return abortedMap.get(this); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(AbortSignal, "none", { | ||
/** | ||
* Creates a new AbortSignal instance that will never be aborted. | ||
* | ||
* @readonly | ||
*/ | ||
get: function () { | ||
return new AbortSignal(); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* Status of whether aborted or not. | ||
* | ||
* @readonly | ||
*/ | ||
get aborted() { | ||
if (!abortedMap.has(this)) { | ||
throw new TypeError("Expected `this` to be an instance of AbortSignal."); | ||
} | ||
return abortedMap.get(this); | ||
} | ||
/** | ||
* Creates a new AbortSignal instance that will never be aborted. | ||
* | ||
* @readonly | ||
*/ | ||
static get none() { | ||
return new AbortSignal(); | ||
} | ||
/** | ||
* Added new "abort" event listener, only support "abort" event. | ||
@@ -69,3 +59,3 @@ * | ||
*/ | ||
AbortSignal.prototype.addEventListener = function ( | ||
addEventListener( | ||
// tslint:disable-next-line:variable-name | ||
@@ -76,5 +66,5 @@ _type, listener) { | ||
} | ||
var listeners = listenersMap.get(this); | ||
const listeners = listenersMap.get(this); | ||
listeners.push(listener); | ||
}; | ||
} | ||
/** | ||
@@ -86,3 +76,3 @@ * Remove "abort" event listener, only support "abort" event. | ||
*/ | ||
AbortSignal.prototype.removeEventListener = function ( | ||
removeEventListener( | ||
// tslint:disable-next-line:variable-name | ||
@@ -93,16 +83,15 @@ _type, listener) { | ||
} | ||
var listeners = listenersMap.get(this); | ||
var index = listeners.indexOf(listener); | ||
const listeners = listenersMap.get(this); | ||
const index = listeners.indexOf(listener); | ||
if (index > -1) { | ||
listeners.splice(index, 1); | ||
} | ||
}; | ||
} | ||
/** | ||
* Dispatches a synthetic event to the AbortSignal. | ||
*/ | ||
AbortSignal.prototype.dispatchEvent = function (_event) { | ||
dispatchEvent(_event) { | ||
throw new Error("This is a stub dispatchEvent implementation that should not be used. It only exists for type-checking purposes."); | ||
}; | ||
return AbortSignal; | ||
}()); | ||
} | ||
} | ||
/** | ||
@@ -125,3 +114,3 @@ * Helper to trigger an abort event immediately, the onabort and all abort event listeners will be triggered. | ||
} | ||
var listeners = listenersMap.get(signal); | ||
const listeners = listenersMap.get(signal); | ||
if (listeners) { | ||
@@ -131,3 +120,3 @@ // Create a copy of listeners so mutations to the array | ||
// we invoke. | ||
listeners.slice().forEach(function (listener) { | ||
listeners.slice().forEach((listener) => { | ||
listener.call(signal, { type: "abort" }); | ||
@@ -158,11 +147,8 @@ }); | ||
*/ | ||
var AbortError = /** @class */ (function (_super) { | ||
tslib.__extends(AbortError, _super); | ||
function AbortError(message) { | ||
var _this = _super.call(this, message) || this; | ||
_this.name = "AbortError"; | ||
return _this; | ||
class AbortError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = "AbortError"; | ||
} | ||
return AbortError; | ||
}(Error)); | ||
} | ||
/** | ||
@@ -202,6 +188,5 @@ * An AbortController provides an AbortSignal and the associated controls to signal | ||
*/ | ||
var AbortController = /** @class */ (function () { | ||
class AbortController { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function AbortController(parentSignals) { | ||
var _this = this; | ||
constructor(parentSignals) { | ||
this._signal = new AbortSignal(); | ||
@@ -216,4 +201,3 @@ if (!parentSignals) { | ||
} | ||
for (var _i = 0, parentSignals_1 = parentSignals; _i < parentSignals_1.length; _i++) { | ||
var parentSignal = parentSignals_1[_i]; | ||
for (const parentSignal of parentSignals) { | ||
// if the parent signal has already had abort() called, | ||
@@ -226,4 +210,4 @@ // then call abort on this signal as well. | ||
// when the parent signal aborts, this signal should as well. | ||
parentSignal.addEventListener("abort", function () { | ||
_this.abort(); | ||
parentSignal.addEventListener("abort", () => { | ||
this.abort(); | ||
}); | ||
@@ -233,22 +217,18 @@ } | ||
} | ||
Object.defineProperty(AbortController.prototype, "signal", { | ||
/** | ||
* The AbortSignal associated with this controller that will signal aborted | ||
* when the abort method is called on this controller. | ||
* | ||
* @readonly | ||
*/ | ||
get: function () { | ||
return this._signal; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
* The AbortSignal associated with this controller that will signal aborted | ||
* when the abort method is called on this controller. | ||
* | ||
* @readonly | ||
*/ | ||
get signal() { | ||
return this._signal; | ||
} | ||
/** | ||
* Signal that any operations passed this controller's associated abort signal | ||
* to cancel any remaining work and throw an `AbortError`. | ||
*/ | ||
AbortController.prototype.abort = function () { | ||
abort() { | ||
abortSignal(this._signal); | ||
}; | ||
} | ||
/** | ||
@@ -258,5 +238,5 @@ * Creates a new AbortSignal instance that will abort after the provided ms. | ||
*/ | ||
AbortController.timeout = function (ms) { | ||
var signal = new AbortSignal(); | ||
var timer = setTimeout(abortSignal, ms, signal); | ||
static timeout(ms) { | ||
const signal = new AbortSignal(); | ||
const timer = setTimeout(abortSignal, ms, signal); | ||
// Prevent the active Timer from keeping the Node.js event loop active. | ||
@@ -267,5 +247,4 @@ if (typeof timer.unref === "function") { | ||
return signal; | ||
}; | ||
return AbortController; | ||
}()); | ||
} | ||
} | ||
@@ -272,0 +251,0 @@ exports.AbortController = AbortController; |
{ | ||
"name": "@azure/abort-controller", | ||
"sdk-type": "client", | ||
"version": "1.0.5-alpha.20210615.1", | ||
"version": "1.0.5-alpha.20210617.1", | ||
"description": "Microsoft Azure SDK for JavaScript - Aborter", | ||
@@ -6,0 +6,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64028
796