@microsoft/1ds-core-js 3.2.11 → 4.0.0
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/README.md +1 -1
- package/bundle/es5/ms.core-4.0.0.gbl.js +6221 -0
- package/bundle/es5/ms.core-4.0.0.gbl.js.map +1 -0
- package/bundle/es5/ms.core-4.0.0.gbl.min.js +7 -0
- package/bundle/es5/ms.core-4.0.0.gbl.min.js.map +1 -0
- package/bundle/es5/ms.core-4.0.0.integrity.json +46 -0
- package/bundle/es5/ms.core-4.0.0.js +6225 -0
- package/bundle/es5/ms.core-4.0.0.js.map +1 -0
- package/bundle/es5/ms.core-4.0.0.min.js +7 -0
- package/bundle/es5/ms.core-4.0.0.min.js.map +1 -0
- package/bundle/es5/ms.core.gbl.js +6221 -0
- package/bundle/es5/ms.core.gbl.js.map +1 -0
- package/bundle/es5/ms.core.gbl.min.js +7 -0
- package/bundle/es5/ms.core.gbl.min.js.map +1 -0
- package/bundle/es5/ms.core.integrity.json +46 -0
- package/bundle/es5/ms.core.js +6225 -0
- package/bundle/es5/ms.core.js.map +1 -0
- package/bundle/es5/ms.core.min.js +7 -0
- package/bundle/es5/ms.core.min.js.map +1 -0
- package/{bundle → dist/es5}/ms.core.js +3790 -2967
- package/dist/es5/ms.core.js.map +1 -0
- package/dist/es5/ms.core.min.js +7 -0
- package/dist/es5/ms.core.min.js.map +1 -0
- package/dist-es5/AppInsightsCore.js +91 -0
- package/dist-es5/AppInsightsCore.js.map +1 -0
- package/{dist-esm/src → dist-es5}/BaseCore.js +18 -11
- package/dist-es5/BaseCore.js.map +1 -0
- package/{dist-esm/src → dist-es5}/DataModels.js +1 -1
- package/{dist-esm/src → dist-es5}/Enums.js +3 -26
- package/dist-es5/Enums.js.map +1 -0
- package/{dist-esm/src → dist-es5}/Index.js +9 -14
- package/dist-es5/Index.js.map +1 -0
- package/{dist-esm/src → dist-es5}/InternalConstants.js +1 -3
- package/{dist-esm/src → dist-es5}/InternalConstants.js.map +1 -1
- package/{dist-esm/src → dist-es5}/Utils.js +19 -144
- package/dist-es5/Utils.js.map +1 -0
- package/{dist-esm/src → dist-es5}/ValueSanitizer.js +39 -3
- package/dist-es5/ValueSanitizer.js.map +1 -0
- package/package.json +16 -9
- package/tsconfig.json +5 -3
- package/types/1ds-core-js.d.ts +1106 -0
- package/types/1ds-core-js.namespaced.d.ts +1102 -0
- package/bundle/ms.core-3.2.11.gbl.js +0 -5378
- package/bundle/ms.core-3.2.11.gbl.js.map +0 -1
- package/bundle/ms.core-3.2.11.gbl.min.js +0 -7
- package/bundle/ms.core-3.2.11.gbl.min.js.map +0 -1
- package/bundle/ms.core-3.2.11.integrity.json +0 -46
- package/bundle/ms.core-3.2.11.js +0 -5381
- package/bundle/ms.core-3.2.11.js.map +0 -1
- package/bundle/ms.core-3.2.11.min.js +0 -7
- package/bundle/ms.core-3.2.11.min.js.map +0 -1
- package/bundle/ms.core.gbl.js +0 -5378
- package/bundle/ms.core.gbl.js.map +0 -1
- package/bundle/ms.core.gbl.min.js +0 -7
- package/bundle/ms.core.gbl.min.js.map +0 -1
- package/bundle/ms.core.integrity.json +0 -46
- package/bundle/ms.core.js.map +0 -1
- package/bundle/ms.core.min.js +0 -7
- package/bundle/ms.core.min.js.map +0 -1
- package/dist/ms.core.js +0 -1305
- package/dist/ms.core.js.map +0 -1
- package/dist/ms.core.min.js +0 -7
- package/dist/ms.core.min.js.map +0 -1
- package/dist-esm/src/AppInsightsCore.d.ts +0 -15
- package/dist-esm/src/AppInsightsCore.js +0 -114
- package/dist-esm/src/AppInsightsCore.js.map +0 -1
- package/dist-esm/src/BaseCore.d.ts +0 -13
- package/dist-esm/src/BaseCore.js.map +0 -1
- package/dist-esm/src/DataModels.d.ts +0 -273
- package/dist-esm/src/ESPromise.d.ts +0 -110
- package/dist-esm/src/ESPromise.js +0 -286
- package/dist-esm/src/ESPromise.js.map +0 -1
- package/dist-esm/src/ESPromiseScheduler.d.ts +0 -36
- package/dist-esm/src/ESPromiseScheduler.js +0 -274
- package/dist-esm/src/ESPromiseScheduler.js.map +0 -1
- package/dist-esm/src/Enums.d.ts +0 -356
- package/dist-esm/src/Enums.js.map +0 -1
- package/dist-esm/src/Index.d.ts +0 -19
- package/dist-esm/src/Index.js.map +0 -1
- package/dist-esm/src/InternalConstants.d.ts +0 -6
- package/dist-esm/src/Utils.d.ts +0 -190
- package/dist-esm/src/Utils.js.map +0 -1
- package/dist-esm/src/ValueSanitizer.d.ts +0 -40
- package/dist-esm/src/ValueSanitizer.js.map +0 -1
- package/src/AppInsightsCore.ts +0 -135
- package/src/BaseCore.ts +0 -72
- package/src/DataModels.ts +0 -297
- package/src/ESPromise.ts +0 -365
- package/src/ESPromiseScheduler.ts +0 -328
- package/src/Enums.ts +0 -386
- package/src/Index.ts +0 -81
- package/src/InternalConstants.ts +0 -16
- package/src/Utils.ts +0 -565
- package/src/ValueSanitizer.ts +0 -285
- /package/{dist-esm/src → dist-es5}/DataModels.js.map +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ESPromise.js.map","sources":["ESPromise.js"],"sourcesContent":["/**\r\n* ESPromise.ts\r\n* @author Nev Wylie (newylie))\r\n* @copyright Microsoft 2019\r\n* Simplified wrapper to provide ES6 style Promise callback handling for older browsers\r\n*/\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { isFunction } from \"@microsoft/applicationinsights-core-js\";\r\n/**\r\n * @ignore -- Don't include in the generated documentation\r\n * Using a local variable to assist with minfication\r\n */\r\nvar _isFunction = isFunction;\r\n/**\r\n * @ignore -- Don't include in the generated documentation\r\n * This function will be used as onFulfilled handler for any Promise found in the iterable passed to Promise.all.\r\n * The goal here is to capture in a closure the index of the current item from the iterable. If we did not create\r\n * this closure, the captured index variable would be the same one that the for loop updates and thus would always\r\n * be pointing to the last index in the iterable by the time that the onFulfilled handler is called.\r\n * However, note that for the resolvedCallback callback we want the opposite. For this one we do want to capture\r\n * the same variable that the for loop updates so that we have the full count of pending promises by the time\r\n * the onFulfilled handlers start getting called.\r\n * @param values The resolving promise values\r\n * @param index The index of this callback function\r\n * @param resolvedCallback THe callback function used to check if the \"all\" promise is complete\r\n */\r\nfunction _createPromiseAllOnResolvedFunction(values, index, resolvedCallback) {\r\n return function (value) {\r\n values[index] = value;\r\n resolvedCallback();\r\n };\r\n}\r\n/**\r\n * Simplified wrapper to provide ES6 style Promise callback handling for older browsers\r\n */\r\nvar ESPromise = /** @class */ (function () {\r\n /**\r\n * The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.\r\n * @param resolverFunc A function that is passed with the arguments resolve and reject. The executor function is executed\r\n * immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise\r\n * constructor even returns the created object). The resolve and reject functions, when called, resolve or reject the promise,\r\n * respectively. The executor normally initiates some asynchronous work, and then, once that completes, either calls the resolve\r\n * function to resolve the promise or else rejects it if an error occurred. If an error is thrown in the executor function, the\r\n * promise is rejected. The return value of the executor is ignored.\r\n */\r\n function ESPromise(resolverFunc) {\r\n var _state = 0 /* PromiseState.Pending */;\r\n var _settledValue = null;\r\n var _queue = [];\r\n dynamicProto(ESPromise, this, function (_this) {\r\n _this.then = function (onResolved, onRejected) {\r\n return new ESPromise(function (resolve, reject) {\r\n // Queue the new promise returned to be resolved or rejected\r\n // when this promise settles.\r\n _enqueue(onResolved, onRejected, resolve, reject);\r\n });\r\n };\r\n _this[\"catch\"] = function (onRejected) {\r\n return _this.then(null, onRejected);\r\n };\r\n });\r\n function _enqueue(onResolved, onRejected, resolve, reject) {\r\n _queue.push(function () {\r\n var value;\r\n try {\r\n // First call the onFulfilled or onRejected handler, on the settled value\r\n // of this promise. If the corresponding handler does not exist, simply\r\n // pass through the settled value.\r\n if (_state === 1 /* PromiseState.Resolved */) {\r\n value = _isFunction(onResolved) ? onResolved(_settledValue) : _settledValue;\r\n }\r\n else {\r\n value = _isFunction(onRejected) ? onRejected(_settledValue) : _settledValue;\r\n }\r\n if (value instanceof ESPromise) {\r\n // The called handlers returned a new promise, so the chained promise\r\n // will follow the state of this promise.\r\n value.then(resolve, reject);\r\n }\r\n else if (_state === 2 /* PromiseState.Rejected */ && !_isFunction(onRejected)) {\r\n // If there wasn't an onRejected handler and this promise is rejected, then\r\n // the chained promise also rejects with the same reason.\r\n reject(value);\r\n }\r\n else {\r\n // If this promise is fulfilled, then the chained promise is also fulfilled\r\n // with either the settled value of this promise (if no onFulfilled handler\r\n // was available) or the return value of the handler. If this promise is\r\n // rejected and there was an onRejected handler, then the chained promise is\r\n // fulfilled with the return value of the handler.\r\n resolve(value);\r\n }\r\n }\r\n catch (error) {\r\n // The chained promise will reject if there is any exception thrown while\r\n // calling the onFulfilled or onRejected handlers.\r\n reject(error);\r\n return;\r\n }\r\n });\r\n // If this promise is already settled, then immediately process the callback we\r\n // just added to the queue.\r\n if (_state !== 0 /* PromiseState.Pending */) {\r\n _processQueue();\r\n }\r\n }\r\n function _processQueue() {\r\n if (_queue.length > 0) {\r\n // The onFulfilled and onRejected handlers must be called asynchronously. Thus,\r\n // we make a copy of the queue and work on it once the current call stack unwinds.\r\n var pending_1 = _queue.slice();\r\n _queue = [];\r\n setTimeout(function () {\r\n for (var i = 0, len = pending_1.length; i < len; ++i) {\r\n try {\r\n pending_1[i]();\r\n }\r\n catch (e) {\r\n // Don't let 1 failing handler break all others\r\n // TODO (newylie): Add some form of error reporting (i.e. Call any registered JS error handler so the error is reported)\r\n }\r\n }\r\n }, 0);\r\n }\r\n }\r\n function _resolve(value) {\r\n if (_state === 0 /* PromiseState.Pending */) {\r\n _settledValue = value;\r\n _state = 1 /* PromiseState.Resolved */;\r\n _processQueue();\r\n }\r\n }\r\n function _reject(reason) {\r\n if (_state === 0 /* PromiseState.Pending */) {\r\n _settledValue = reason;\r\n _state = 2 /* PromiseState.Rejected */;\r\n _processQueue();\r\n }\r\n }\r\n (function _initialize() {\r\n if (!_isFunction(resolverFunc)) {\r\n throw new TypeError(\"ESPromise: resolvedFunc argument is not a Function\");\r\n }\r\n try {\r\n resolverFunc(_resolve, _reject);\r\n }\r\n catch (error) {\r\n // This promise will immediately reject if any exception is thrown\r\n // from within the executor function.\r\n _reject(error);\r\n }\r\n })();\r\n }\r\n /**\r\n * The Promise.resolve() method returns a Promise object that is resolved with a given value. If the value is a promise, that promise is returned;\r\n * if the value is a thenable (i.e. has a \"then\" method), the returned promise will \"follow\" that thenable, adopting its eventual state; otherwise\r\n * the returned promise will be fulfilled with the value. This function flattens nested layers of promise-like objects (e.g. a promise that resolves\r\n * to a promise that resolves to something) into a single layer.\r\n * @param value Argument to be resolved by this Promise. Can also be a Promise or a thenable to resolve.\r\n */\r\n ESPromise.resolve = function (value) {\r\n if (value instanceof ESPromise) {\r\n // Value is a Promise so just return it\r\n return value;\r\n }\r\n else if (value && _isFunction(value.then)) {\r\n // Value looks like a promise or thenable (has a then function)\r\n return new ESPromise(function (resolve, reject) {\r\n try {\r\n value.then(resolve, reject);\r\n }\r\n catch (error) {\r\n reject(error);\r\n }\r\n });\r\n }\r\n return new ESPromise(function (resolve) {\r\n resolve(value);\r\n });\r\n };\r\n /**\r\n * The Promise.reject() method returns a Promise object that is rejected with a given reason.\r\n * @param reason The reason why this Promise rejected.\r\n */\r\n ESPromise.reject = function (reason) {\r\n return new ESPromise(function (resolve, reject) {\r\n reject(reason);\r\n });\r\n };\r\n /**\r\n * The Promise.all() method returns a single Promise that resolves when all of the promises passed as an iterable\r\n * have resolved or when the iterable contains no promises. It rejects with the reason of the first promise that\r\n * rejects. There is no implied ordering in the execution of the array of Promises given. On some computers, they\r\n * may be executed in parallel, or in some sense concurrently, while on others they may be executed serially. For\r\n * this reason, there must be no dependency in any Promise on the order of execution of the Promises.\r\n * This method can be useful for aggregating the results of multiple promises.\r\n * FulfillmentSection - The returned promise is fulfilled with an array containing all the values of the iterable\r\n * passed as argument (also non-promise values).\r\n * If an empty iterable is passed, then this method returns (synchronously) an already resolved promise.\r\n * If all of the passed-in promises fulfill, or are not promises, the promise returned by Promise.all is fulfilled\r\n * asynchronously.\r\n * RejectionSection - If any of the passed-in promises reject, Promise.all asynchronously rejects with the value of\r\n * the promise that rejected, whether or not the other promises have resolved.\r\n * @param iterable\r\n */\r\n ESPromise.all = function (iterable) {\r\n if (!iterable || !iterable.length) {\r\n return;\r\n }\r\n return new ESPromise(function (resolve, reject) {\r\n try {\r\n var values_1 = [];\r\n var pending_2 = 0;\r\n for (var lp = 0; lp < iterable.length; lp++) {\r\n var item = iterable[lp];\r\n // Quick and direct check for a Promise (will also catch a thenable)\r\n if (item && _isFunction(item.then)) {\r\n pending_2++;\r\n item.then(_createPromiseAllOnResolvedFunction(values_1, lp, function () {\r\n if (--pending_2 === 0) {\r\n resolve(values_1);\r\n }\r\n }), reject);\r\n }\r\n else {\r\n values_1[lp] = item;\r\n }\r\n }\r\n if (pending_2 === 0) {\r\n // All promises were either resolved or where not a promise\r\n setTimeout(function () {\r\n resolve(values_1);\r\n }, 0);\r\n }\r\n }\r\n catch (error) {\r\n reject(error);\r\n }\r\n });\r\n };\r\n /**\r\n * The race function returns a Promise that is settled the same way (and takes the same value) as the first promise\r\n * that settles amongst the promises of the iterable passed as an argument.\r\n * If the iterable passed is empty, the promise returned will be forever pending.\r\n * If the iterable contains one or more non-promise value and/or an already settled promise, then Promise.race will\r\n * resolve to the first of these values found in the iterable.\r\n * @param iterable\r\n */\r\n ESPromise.race = function (iterable) {\r\n return new ESPromise(function (resolve, reject) {\r\n if (!iterable || !iterable.length) {\r\n return;\r\n }\r\n try {\r\n var _loop_1 = function (lp) {\r\n var item = iterable[lp];\r\n // Quick and direct check for a Promise (will also catch a thenable)\r\n if (item && _isFunction(item.then)) {\r\n item.then(resolve, reject);\r\n }\r\n else {\r\n setTimeout(function () {\r\n resolve(item);\r\n }, 0);\r\n }\r\n };\r\n for (var lp = 0; lp < iterable.length; lp++) {\r\n _loop_1(lp);\r\n }\r\n }\r\n catch (error) {\r\n reject(error);\r\n }\r\n });\r\n };\r\n /**\r\n * The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise.\r\n * @param onResolved A Function called if the Promise is fulfilled. This function has one argument, the fulfillment value. If it is not a\r\n * function, it is internally replaced with an \"Identity\" function (it returns the received argument).\r\n * @param onRejected A Function called if the Promise is rejected. This function has one argument, the rejection reason. If it is not a\r\n * function, it is internally replaced with a \"Thrower\" function (it throws an error it received as argument).\r\n * @returns Once a Promise is fulfilled or rejected, the respective handler function (onFulfilled or onRejected) will be called asynchronously\r\n * (scheduled in the current thread loop). The behavior of the handler function follows a specific set of rules. If a handler function:\r\n * - returns a value, the promise returned by then gets resolved with the returned value as its value;\r\n * - doesn't return anything, the promise returned by then gets resolved with an undefined value;\r\n * - throws an error, the promise returned by then gets rejected with the thrown error as its value;\r\n * - returns an already fulfilled promise, the promise returned by then gets fulfilled with that promise's value as its value;\r\n * - returns an already rejected promise, the promise returned by then gets rejected with that promise's value as its value;\r\n * - returns another pending promise object, the resolution/rejection of the promise returned by then will be subsequent to the\r\n * resolution/rejection of the promise returned by the handler. Also, the value of the promise returned by then will be the same as the value of the promise returned by the handler.\r\n */\r\n ESPromise.prototype.then = function (onResolved, onRejected) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return;\r\n };\r\n /**\r\n * The catch() method returns a Promise and deals with rejected cases only. It behaves the same as calling Promise.prototype.then(undefined, onRejected)\r\n * (in fact, calling obj.catch(onRejected) internally calls obj.then(undefined, onRejected)). This means that you have to provide an onRejected function\r\n * even if you want to fall back to an undefined result value - for example obj.catch(() => {}).\r\n * @param onRejected A Function called when the Promise is rejected. This function has one argument: reason The rejection reason.\r\n * @returns Internally calls Promise.prototype.then on the object upon which it was called, passing the parameters undefined and the received\r\n * onRejected handler. Returns the value of that call, which is a Promise.\r\n */\r\n ESPromise.prototype[\"catch\"] = function (onRejected) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return;\r\n };\r\n return ESPromise;\r\n}());\r\nexport default ESPromise;\r\n//# sourceMappingURL=ESPromise.js.map"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;iDA+BM;AACN;AACA;AACA;AACA"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESPromiseScheduler.ts
|
|
3
|
-
* @author Nev Wylie (newylie)
|
|
4
|
-
* @copyright Microsoft 2019
|
|
5
|
-
*/
|
|
6
|
-
import ESPromise from "./ESPromise";
|
|
7
|
-
import { IDiagnosticLogger } from "@microsoft/applicationinsights-core-js";
|
|
8
|
-
export type ESPromiseSchedulerEvent<T> = (eventId?: string) => ESPromise<T>;
|
|
9
|
-
export interface IScheduledEventDetails {
|
|
10
|
-
evt: ESPromise<any>;
|
|
11
|
-
tm: number;
|
|
12
|
-
wTm?: number;
|
|
13
|
-
id: string;
|
|
14
|
-
to?: any;
|
|
15
|
-
isRunning: boolean;
|
|
16
|
-
isAborted: boolean;
|
|
17
|
-
abort?: (message: string) => void;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Provides a simple mechanism queueing mechanism for scheduling events based on the ESPromise callbacks, this is used to ensure
|
|
21
|
-
* order of async operations that are required to be executed in a specific order.
|
|
22
|
-
*/
|
|
23
|
-
export default class ESPromiseScheduler {
|
|
24
|
-
static incomplete(): IScheduledEventDetails[];
|
|
25
|
-
static waitingToStart(): IScheduledEventDetails[];
|
|
26
|
-
constructor(name?: string, diagLog?: IDiagnosticLogger);
|
|
27
|
-
/**
|
|
28
|
-
* Schedule an event that will execute the startEvent after all outstanding events are resolved or rejected. This is used to ensure
|
|
29
|
-
* order of async operations that are required to be executed in a specific order.
|
|
30
|
-
* The returned promise will be resolve or rejected based on the values returned from the doAction.
|
|
31
|
-
* @param startEventAction The function to execute to start the event after all outstanding events have completed, will be called asynchronously.
|
|
32
|
-
* @param eventName An [Optional] event name to assist with debbuging to understand what events are either waiting to start or still running (incomplete).
|
|
33
|
-
* @param timeout An [Optional] timeout
|
|
34
|
-
*/
|
|
35
|
-
scheduleEvent<T>(startEventAction: ESPromiseSchedulerEvent<T>, eventName?: string, timeout?: number): ESPromise<T>;
|
|
36
|
-
}
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* 1DS JS SDK Core, 3.2.11
|
|
3
|
-
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
|
-
* (Microsoft Internal Only)
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* ESPromiseScheduler.ts
|
|
8
|
-
* @author Nev Wylie (newylie)
|
|
9
|
-
* @copyright Microsoft 2019
|
|
10
|
-
*/
|
|
11
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
12
|
-
import ESPromise from "./ESPromise";
|
|
13
|
-
import { _warnToConsole, getGlobal } from "@microsoft/applicationinsights-core-js";
|
|
14
|
-
/** This is a default timeout that will cause outstanding running promises to be removed/rejected to avoid filling up memory with blocked events */
|
|
15
|
-
var LazyRejectPeriod = 600000; // 10 Minutes
|
|
16
|
-
// These are global variables that are shared across ALL instances of the scheduler
|
|
17
|
-
/**
|
|
18
|
-
* @ignore
|
|
19
|
-
*/
|
|
20
|
-
var _schedulerId = 0;
|
|
21
|
-
/**
|
|
22
|
-
* @ignore
|
|
23
|
-
*/
|
|
24
|
-
var _running = [];
|
|
25
|
-
/**
|
|
26
|
-
* @ignore
|
|
27
|
-
*/
|
|
28
|
-
var _waiting = [];
|
|
29
|
-
/**
|
|
30
|
-
* @ignore
|
|
31
|
-
*/
|
|
32
|
-
var _timedOut = [];
|
|
33
|
-
/**
|
|
34
|
-
* @ignore
|
|
35
|
-
*/
|
|
36
|
-
function _getTime() {
|
|
37
|
-
return new Date().getTime();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Provides a simple mechanism queueing mechanism for scheduling events based on the ESPromise callbacks, this is used to ensure
|
|
41
|
-
* order of async operations that are required to be executed in a specific order.
|
|
42
|
-
*/
|
|
43
|
-
var ESPromiseScheduler = /** @class */ (function () {
|
|
44
|
-
function ESPromiseScheduler(name, diagLog) {
|
|
45
|
-
var _promiseId = 0;
|
|
46
|
-
var _scheduledName = (name || "<unnamed>") + "." + _schedulerId;
|
|
47
|
-
_schedulerId++;
|
|
48
|
-
dynamicProto(ESPromiseScheduler, this, function (_this) {
|
|
49
|
-
var _lastEvent = null;
|
|
50
|
-
var _eventCount = 0;
|
|
51
|
-
_this.scheduleEvent = function (startEventAction, eventName, timeout) {
|
|
52
|
-
var uniqueId = _scheduledName + "." + _eventCount;
|
|
53
|
-
_eventCount++;
|
|
54
|
-
if (eventName) {
|
|
55
|
-
uniqueId += "-(" + eventName + ")";
|
|
56
|
-
}
|
|
57
|
-
var uniqueEventId = uniqueId + "{" + _promiseId + "}";
|
|
58
|
-
_promiseId++;
|
|
59
|
-
// Create the next scheduled event details
|
|
60
|
-
var newScheduledEvent = {
|
|
61
|
-
evt: null,
|
|
62
|
-
tm: _getTime(),
|
|
63
|
-
id: uniqueEventId,
|
|
64
|
-
isRunning: false,
|
|
65
|
-
isAborted: false
|
|
66
|
-
};
|
|
67
|
-
if (!_lastEvent) {
|
|
68
|
-
// We don't have any currently running event, so just start the next event
|
|
69
|
-
newScheduledEvent.evt = _startWaitingEvent(newScheduledEvent);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
// Start a new promise which will wait until all current active events are complete before starting
|
|
73
|
-
// the new event, it does not resolve this scheduled event until after the new event is resolve to
|
|
74
|
-
// ensure that all scheduled events are completed in the correct order
|
|
75
|
-
newScheduledEvent.evt = _waitForPreviousEvent(newScheduledEvent, _lastEvent);
|
|
76
|
-
}
|
|
77
|
-
// Set this new event as the last one, so that any future events will wait for this one
|
|
78
|
-
_lastEvent = newScheduledEvent;
|
|
79
|
-
_lastEvent.evt._schId = uniqueEventId;
|
|
80
|
-
return newScheduledEvent.evt;
|
|
81
|
-
function _abortAndRemoveOldEvents(eventQueue) {
|
|
82
|
-
var now = _getTime();
|
|
83
|
-
var expired = now - LazyRejectPeriod;
|
|
84
|
-
var len = eventQueue.length;
|
|
85
|
-
var lp = 0;
|
|
86
|
-
while (lp < len) {
|
|
87
|
-
var evt = eventQueue[lp];
|
|
88
|
-
if (evt && evt.tm < expired) {
|
|
89
|
-
var message = null;
|
|
90
|
-
if (evt.abort) {
|
|
91
|
-
message = "Aborting [" + evt.id + "] due to Excessive runtime (" + (now - evt.tm) + " ms)";
|
|
92
|
-
evt.abort(message);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
message = "Removing [" + evt.id + "] due to Excessive runtime (" + (now - evt.tm) + " ms)";
|
|
96
|
-
}
|
|
97
|
-
_warnLog(message);
|
|
98
|
-
eventQueue.splice(lp, 1);
|
|
99
|
-
len--;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
lp++;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
function _cleanup(eventId, completed) {
|
|
107
|
-
var toQueue = false;
|
|
108
|
-
var removed = _removeQueuedEvent(_running, eventId);
|
|
109
|
-
if (!removed) {
|
|
110
|
-
removed = _removeQueuedEvent(_timedOut, eventId);
|
|
111
|
-
toQueue = true;
|
|
112
|
-
}
|
|
113
|
-
if (removed) {
|
|
114
|
-
if (removed.to) {
|
|
115
|
-
// If there was a timeout stop it
|
|
116
|
-
clearTimeout(removed.to);
|
|
117
|
-
removed.to = null;
|
|
118
|
-
}
|
|
119
|
-
// TODO (newylie): Convert this into reportable metrics
|
|
120
|
-
var tm = _getTime() - removed.tm;
|
|
121
|
-
if (completed) {
|
|
122
|
-
if (!toQueue) {
|
|
123
|
-
_debugLog("Promise [" + eventId + "] Complete -- " + tm + " ms");
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
_warnLog("Timed out event [" + eventId + "] finally complete -- " + tm + " ms");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
_timedOut.push(removed);
|
|
131
|
-
_warnLog("Event [" + eventId + "] Timed out and removed -- " + tm + " ms");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
_debugLog("Failed to remove [" + eventId + "] from running queue");
|
|
136
|
-
}
|
|
137
|
-
// Also if the last scheduled event was this event then clear it as we are now finished
|
|
138
|
-
if (_lastEvent && _lastEvent.id === eventId) {
|
|
139
|
-
_lastEvent = null;
|
|
140
|
-
}
|
|
141
|
-
_abortAndRemoveOldEvents(_running);
|
|
142
|
-
_abortAndRemoveOldEvents(_waiting);
|
|
143
|
-
_abortAndRemoveOldEvents(_timedOut);
|
|
144
|
-
}
|
|
145
|
-
// Return a callback function that will be called when the waiting promise is resolved or rejected to ensure
|
|
146
|
-
// that any outer promise is also resolved or rejected
|
|
147
|
-
function _removeScheduledEvent(eventId, callback) {
|
|
148
|
-
return function (value) {
|
|
149
|
-
_cleanup(eventId, true);
|
|
150
|
-
callback && callback(value);
|
|
151
|
-
return value;
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function _waitForFinalResult(eventId, startResult, schEventResolve, schEventReject) {
|
|
155
|
-
startResult.then(function (value) {
|
|
156
|
-
if (value instanceof ESPromise) {
|
|
157
|
-
// If the result is a promise then this appears to be a chained result, so wait for this promise to complete
|
|
158
|
-
_debugLog("Event [" + eventId + "] returned a promise -- waiting");
|
|
159
|
-
_waitForFinalResult(eventId, value, schEventResolve, schEventReject);
|
|
160
|
-
return value;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
return _removeScheduledEvent(eventId, schEventResolve)(value);
|
|
164
|
-
}
|
|
165
|
-
}, _removeScheduledEvent(eventId, schEventReject));
|
|
166
|
-
}
|
|
167
|
-
// Add the passed event to the active event list with resolve and reject callbacks that will remove
|
|
168
|
-
// it from the active event list
|
|
169
|
-
function _createScheduledEvent(eventDetails, startEvent) {
|
|
170
|
-
var eventId = eventDetails.id;
|
|
171
|
-
return new ESPromise(function (schEventResolve, schEventReject) {
|
|
172
|
-
_debugLog("Event [" + eventId + "] Starting -- waited for " + (eventDetails.wTm || "--") + " ms");
|
|
173
|
-
eventDetails.isRunning = true;
|
|
174
|
-
eventDetails.abort = function (message) {
|
|
175
|
-
eventDetails.abort = null;
|
|
176
|
-
eventDetails.isAborted = true;
|
|
177
|
-
_cleanup(eventId, false);
|
|
178
|
-
schEventReject(new Error(message));
|
|
179
|
-
};
|
|
180
|
-
var startResult = startEvent(eventId);
|
|
181
|
-
if (startResult instanceof ESPromise) {
|
|
182
|
-
if (timeout) {
|
|
183
|
-
// Note: Only starting a timer if a timeout was specified
|
|
184
|
-
eventDetails.to = setTimeout(function () {
|
|
185
|
-
_cleanup(eventId, false);
|
|
186
|
-
// Cause the listeners to reject (Note: We can't actually reject the waiting event)
|
|
187
|
-
schEventReject(new Error("Timed out after [" + timeout + "] ms"));
|
|
188
|
-
}, timeout);
|
|
189
|
-
}
|
|
190
|
-
_waitForFinalResult(eventId, startResult, function (theResult) {
|
|
191
|
-
_debugLog("Event [" + eventId + "] Resolving after " + (_getTime() - eventDetails.tm) + " ms");
|
|
192
|
-
schEventResolve(theResult);
|
|
193
|
-
}, schEventReject);
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
// The startEvent didn't return a promise so just return a resolved promise
|
|
197
|
-
_debugLog("Promise [" + eventId + "] Auto completed as the start action did not return a promise");
|
|
198
|
-
schEventResolve();
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
function _startWaitingEvent(eventDetails) {
|
|
203
|
-
var now = _getTime();
|
|
204
|
-
eventDetails.wTm = now - eventDetails.tm;
|
|
205
|
-
eventDetails.tm = now;
|
|
206
|
-
if (eventDetails.isAborted) {
|
|
207
|
-
return ESPromise.reject(new Error("[" + uniqueId + "] was aborted"));
|
|
208
|
-
}
|
|
209
|
-
_running.push(eventDetails);
|
|
210
|
-
return _createScheduledEvent(eventDetails, startEventAction);
|
|
211
|
-
}
|
|
212
|
-
// Start a new promise which will wait until all current active events are complete before starting
|
|
213
|
-
// the new event, it does not resolve this scheduled event until after the new event is resolve to
|
|
214
|
-
// ensure that all scheduled events are completed in the correct order
|
|
215
|
-
function _waitForPreviousEvent(eventDetails, waitForEvent) {
|
|
216
|
-
var waitEvent = new ESPromise(function (waitResolve, waitReject) {
|
|
217
|
-
var runTime = _getTime() - waitForEvent.tm;
|
|
218
|
-
var prevId = waitForEvent.id;
|
|
219
|
-
_debugLog("[" + uniqueId + "] is waiting for [" + prevId + ":" + runTime + " ms] to complete before starting -- [" + _waiting.length + "] waiting and [" + _running.length + "] running");
|
|
220
|
-
eventDetails.abort = function (message) {
|
|
221
|
-
eventDetails.abort = null;
|
|
222
|
-
_removeQueuedEvent(_waiting, uniqueId);
|
|
223
|
-
eventDetails.isAborted = true;
|
|
224
|
-
waitReject(new Error(message));
|
|
225
|
-
};
|
|
226
|
-
// Wait for the previous event to complete
|
|
227
|
-
waitForEvent.evt.then(function (value) {
|
|
228
|
-
_removeQueuedEvent(_waiting, uniqueId);
|
|
229
|
-
// Wait for the last event to complete before starting the new one, this ensures the execution
|
|
230
|
-
// order so that we don't try and remove events that havn't been committed yet
|
|
231
|
-
_startWaitingEvent(eventDetails).then(waitResolve, waitReject);
|
|
232
|
-
}, function (reason) {
|
|
233
|
-
_removeQueuedEvent(_waiting, uniqueId);
|
|
234
|
-
// Wait for the last event to complete before starting the new one, this ensures the execution
|
|
235
|
-
// order so that we don't try and remove events that havn't been committed yet
|
|
236
|
-
_startWaitingEvent(eventDetails).then(waitResolve, waitReject);
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
_waiting.push(eventDetails);
|
|
240
|
-
return waitEvent;
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
function _removeQueuedEvent(queue, eventId) {
|
|
244
|
-
for (var lp = 0; lp < queue.length; lp++) {
|
|
245
|
-
if (queue[lp].id === eventId) {
|
|
246
|
-
return queue.splice(lp, 1)[0];
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
function _debugLog(message) {
|
|
253
|
-
// Only log if running within test harness
|
|
254
|
-
var global = getGlobal();
|
|
255
|
-
if (global && global["QUnit"]) {
|
|
256
|
-
// tslint:disable-next-line:no-console
|
|
257
|
-
console && console.log("ESPromiseScheduler[" + _scheduledName + "] " + message);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function _warnLog(message) {
|
|
261
|
-
_warnToConsole(diagLog, "ESPromiseScheduler[" + _scheduledName + "] " + message);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
ESPromiseScheduler.incomplete = function () {
|
|
265
|
-
return _running;
|
|
266
|
-
};
|
|
267
|
-
ESPromiseScheduler.waitingToStart = function () {
|
|
268
|
-
return _waiting;
|
|
269
|
-
};
|
|
270
|
-
// Removed Stub for ESPromiseScheduler.prototype.scheduleEvent.
|
|
271
|
-
return ESPromiseScheduler;
|
|
272
|
-
}());
|
|
273
|
-
export default ESPromiseScheduler;
|
|
274
|
-
//# sourceMappingURL=ESPromiseScheduler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ESPromiseScheduler.js.map","sources":["ESPromiseScheduler.js"],"sourcesContent":["/**\r\n* ESPromiseScheduler.ts\r\n* @author Nev Wylie (newylie)\r\n* @copyright Microsoft 2019\r\n*/\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport ESPromise from \"./ESPromise\";\r\nimport { _warnToConsole, getGlobal } from \"@microsoft/applicationinsights-core-js\";\r\n/** This is a default timeout that will cause outstanding running promises to be removed/rejected to avoid filling up memory with blocked events */\r\nvar LazyRejectPeriod = 600000; // 10 Minutes\r\n// These are global variables that are shared across ALL instances of the scheduler\r\n/**\r\n * @ignore\r\n */\r\nvar _schedulerId = 0;\r\n/**\r\n * @ignore\r\n */\r\nvar _running = [];\r\n/**\r\n * @ignore\r\n */\r\nvar _waiting = [];\r\n/**\r\n * @ignore\r\n */\r\nvar _timedOut = [];\r\n/**\r\n * @ignore\r\n */\r\nfunction _getTime() {\r\n return new Date().getTime();\r\n}\r\n/**\r\n * Provides a simple mechanism queueing mechanism for scheduling events based on the ESPromise callbacks, this is used to ensure\r\n * order of async operations that are required to be executed in a specific order.\r\n */\r\nvar ESPromiseScheduler = /** @class */ (function () {\r\n function ESPromiseScheduler(name, diagLog) {\r\n var _promiseId = 0;\r\n var _scheduledName = (name || \"<unnamed>\") + \".\" + _schedulerId;\r\n _schedulerId++;\r\n dynamicProto(ESPromiseScheduler, this, function (_this) {\r\n var _lastEvent = null;\r\n var _eventCount = 0;\r\n _this.scheduleEvent = function (startEventAction, eventName, timeout) {\r\n var uniqueId = _scheduledName + \".\" + _eventCount;\r\n _eventCount++;\r\n if (eventName) {\r\n uniqueId += \"-(\" + eventName + \")\";\r\n }\r\n var uniqueEventId = uniqueId + \"{\" + _promiseId + \"}\";\r\n _promiseId++;\r\n // Create the next scheduled event details\r\n var newScheduledEvent = {\r\n evt: null,\r\n tm: _getTime(),\r\n id: uniqueEventId,\r\n isRunning: false,\r\n isAborted: false\r\n };\r\n if (!_lastEvent) {\r\n // We don't have any currently running event, so just start the next event\r\n newScheduledEvent.evt = _startWaitingEvent(newScheduledEvent);\r\n }\r\n else {\r\n // Start a new promise which will wait until all current active events are complete before starting\r\n // the new event, it does not resolve this scheduled event until after the new event is resolve to\r\n // ensure that all scheduled events are completed in the correct order\r\n newScheduledEvent.evt = _waitForPreviousEvent(newScheduledEvent, _lastEvent);\r\n }\r\n // Set this new event as the last one, so that any future events will wait for this one\r\n _lastEvent = newScheduledEvent;\r\n _lastEvent.evt._schId = uniqueEventId;\r\n return newScheduledEvent.evt;\r\n function _abortAndRemoveOldEvents(eventQueue) {\r\n var now = _getTime();\r\n var expired = now - LazyRejectPeriod;\r\n var len = eventQueue.length;\r\n var lp = 0;\r\n while (lp < len) {\r\n var evt = eventQueue[lp];\r\n if (evt && evt.tm < expired) {\r\n var message = null;\r\n if (evt.abort) {\r\n message = \"Aborting [\" + evt.id + \"] due to Excessive runtime (\" + (now - evt.tm) + \" ms)\";\r\n evt.abort(message);\r\n }\r\n else {\r\n message = \"Removing [\" + evt.id + \"] due to Excessive runtime (\" + (now - evt.tm) + \" ms)\";\r\n }\r\n _warnLog(message);\r\n eventQueue.splice(lp, 1);\r\n len--;\r\n }\r\n else {\r\n lp++;\r\n }\r\n }\r\n }\r\n function _cleanup(eventId, completed) {\r\n var toQueue = false;\r\n var removed = _removeQueuedEvent(_running, eventId);\r\n if (!removed) {\r\n removed = _removeQueuedEvent(_timedOut, eventId);\r\n toQueue = true;\r\n }\r\n if (removed) {\r\n if (removed.to) {\r\n // If there was a timeout stop it\r\n clearTimeout(removed.to);\r\n removed.to = null;\r\n }\r\n // TODO (newylie): Convert this into reportable metrics\r\n var tm = _getTime() - removed.tm;\r\n if (completed) {\r\n if (!toQueue) {\r\n _debugLog(\"Promise [\" + eventId + \"] Complete -- \" + tm + \" ms\");\r\n }\r\n else {\r\n _warnLog(\"Timed out event [\" + eventId + \"] finally complete -- \" + tm + \" ms\");\r\n }\r\n }\r\n else {\r\n _timedOut.push(removed);\r\n _warnLog(\"Event [\" + eventId + \"] Timed out and removed -- \" + tm + \" ms\");\r\n }\r\n }\r\n else {\r\n _debugLog(\"Failed to remove [\" + eventId + \"] from running queue\");\r\n }\r\n // Also if the last scheduled event was this event then clear it as we are now finished\r\n if (_lastEvent && _lastEvent.id === eventId) {\r\n _lastEvent = null;\r\n }\r\n _abortAndRemoveOldEvents(_running);\r\n _abortAndRemoveOldEvents(_waiting);\r\n _abortAndRemoveOldEvents(_timedOut);\r\n }\r\n // Return a callback function that will be called when the waiting promise is resolved or rejected to ensure\r\n // that any outer promise is also resolved or rejected\r\n function _removeScheduledEvent(eventId, callback) {\r\n return function (value) {\r\n _cleanup(eventId, true);\r\n callback && callback(value);\r\n return value;\r\n };\r\n }\r\n function _waitForFinalResult(eventId, startResult, schEventResolve, schEventReject) {\r\n startResult.then(function (value) {\r\n if (value instanceof ESPromise) {\r\n // If the result is a promise then this appears to be a chained result, so wait for this promise to complete\r\n _debugLog(\"Event [\" + eventId + \"] returned a promise -- waiting\");\r\n _waitForFinalResult(eventId, value, schEventResolve, schEventReject);\r\n return value;\r\n }\r\n else {\r\n return _removeScheduledEvent(eventId, schEventResolve)(value);\r\n }\r\n }, _removeScheduledEvent(eventId, schEventReject));\r\n }\r\n // Add the passed event to the active event list with resolve and reject callbacks that will remove\r\n // it from the active event list\r\n function _createScheduledEvent(eventDetails, startEvent) {\r\n var eventId = eventDetails.id;\r\n return new ESPromise(function (schEventResolve, schEventReject) {\r\n _debugLog(\"Event [\" + eventId + \"] Starting -- waited for \" + (eventDetails.wTm || \"--\") + \" ms\");\r\n eventDetails.isRunning = true;\r\n eventDetails.abort = function (message) {\r\n eventDetails.abort = null;\r\n eventDetails.isAborted = true;\r\n _cleanup(eventId, false);\r\n schEventReject(new Error(message));\r\n };\r\n var startResult = startEvent(eventId);\r\n if (startResult instanceof ESPromise) {\r\n if (timeout) {\r\n // Note: Only starting a timer if a timeout was specified\r\n eventDetails.to = setTimeout(function () {\r\n _cleanup(eventId, false);\r\n // Cause the listeners to reject (Note: We can't actually reject the waiting event)\r\n schEventReject(new Error(\"Timed out after [\" + timeout + \"] ms\"));\r\n }, timeout);\r\n }\r\n _waitForFinalResult(eventId, startResult, function (theResult) {\r\n _debugLog(\"Event [\" + eventId + \"] Resolving after \" + (_getTime() - eventDetails.tm) + \" ms\");\r\n schEventResolve(theResult);\r\n }, schEventReject);\r\n }\r\n else {\r\n // The startEvent didn't return a promise so just return a resolved promise\r\n _debugLog(\"Promise [\" + eventId + \"] Auto completed as the start action did not return a promise\");\r\n schEventResolve();\r\n }\r\n });\r\n }\r\n function _startWaitingEvent(eventDetails) {\r\n var now = _getTime();\r\n eventDetails.wTm = now - eventDetails.tm;\r\n eventDetails.tm = now;\r\n if (eventDetails.isAborted) {\r\n return ESPromise.reject(new Error(\"[\" + uniqueId + \"] was aborted\"));\r\n }\r\n _running.push(eventDetails);\r\n return _createScheduledEvent(eventDetails, startEventAction);\r\n }\r\n // Start a new promise which will wait until all current active events are complete before starting\r\n // the new event, it does not resolve this scheduled event until after the new event is resolve to\r\n // ensure that all scheduled events are completed in the correct order\r\n function _waitForPreviousEvent(eventDetails, waitForEvent) {\r\n var waitEvent = new ESPromise(function (waitResolve, waitReject) {\r\n var runTime = _getTime() - waitForEvent.tm;\r\n var prevId = waitForEvent.id;\r\n _debugLog(\"[\" + uniqueId + \"] is waiting for [\" + prevId + \":\" + runTime + \" ms] to complete before starting -- [\" + _waiting.length + \"] waiting and [\" + _running.length + \"] running\");\r\n eventDetails.abort = function (message) {\r\n eventDetails.abort = null;\r\n _removeQueuedEvent(_waiting, uniqueId);\r\n eventDetails.isAborted = true;\r\n waitReject(new Error(message));\r\n };\r\n // Wait for the previous event to complete\r\n waitForEvent.evt.then(function (value) {\r\n _removeQueuedEvent(_waiting, uniqueId);\r\n // Wait for the last event to complete before starting the new one, this ensures the execution\r\n // order so that we don't try and remove events that havn't been committed yet\r\n _startWaitingEvent(eventDetails).then(waitResolve, waitReject);\r\n }, function (reason) {\r\n _removeQueuedEvent(_waiting, uniqueId);\r\n // Wait for the last event to complete before starting the new one, this ensures the execution\r\n // order so that we don't try and remove events that havn't been committed yet\r\n _startWaitingEvent(eventDetails).then(waitResolve, waitReject);\r\n });\r\n });\r\n _waiting.push(eventDetails);\r\n return waitEvent;\r\n }\r\n };\r\n function _removeQueuedEvent(queue, eventId) {\r\n for (var lp = 0; lp < queue.length; lp++) {\r\n if (queue[lp].id === eventId) {\r\n return queue.splice(lp, 1)[0];\r\n }\r\n }\r\n return null;\r\n }\r\n });\r\n function _debugLog(message) {\r\n // Only log if running within test harness\r\n var global = getGlobal();\r\n if (global && global[\"QUnit\"]) {\r\n // tslint:disable-next-line:no-console\r\n console && console.log(\"ESPromiseScheduler[\" + _scheduledName + \"] \" + message);\r\n }\r\n }\r\n function _warnLog(message) {\r\n _warnToConsole(diagLog, \"ESPromiseScheduler[\" + _scheduledName + \"] \" + message);\r\n }\r\n }\r\n ESPromiseScheduler.incomplete = function () {\r\n return _running;\r\n };\r\n ESPromiseScheduler.waitingToStart = function () {\r\n return _waiting;\r\n };\r\n /**\r\n * Schedule an event that will execute the startEvent after all outstanding events are resolved or rejected. This is used to ensure\r\n * order of async operations that are required to be executed in a specific order.\r\n * The returned promise will be resolve or rejected based on the values returned from the doAction.\r\n * @param startEventAction The function to execute to start the event after all outstanding events have completed, will be called asynchronously.\r\n * @param eventName An [Optional] event name to assist with debbuging to understand what events are either waiting to start or still running (incomplete).\r\n * @param timeout An [Optional] timeout\r\n */\r\n ESPromiseScheduler.prototype.scheduleEvent = function (startEventAction, eventName, timeout) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return;\r\n };\r\n return ESPromiseScheduler;\r\n}());\r\nexport default ESPromiseScheduler;\r\n//# sourceMappingURL=ESPromiseScheduler.js.map"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+DAWM;AACN;AACA;AACA;AACA"}
|