asva-executors
Advanced tools
Comparing version 0.1.11 to 0.1.12
@@ -104,3 +104,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
"use strict"; | ||
eval("__webpack_require__.r(__webpack_exports__);\n!(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\n/* harmony import */ var _Executor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Executor */ \"./src/modules/Executors/Executor.ts\");\n\r\n\r\n/**\r\n * This executor caches first run result and provides it for all subsequent calls.\r\n */\r\nvar CacheExecutor = /** @class */ (function (_super) {\r\n !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(CacheExecutor, _super);\r\n function CacheExecutor() {\r\n var _this = _super !== null && _super.apply(this, arguments) || this;\r\n _this.cachedPromise = null;\r\n return _this;\r\n }\r\n /**\r\n * Run command and cache promise.\r\n */\r\n CacheExecutor.prototype.run = function () {\r\n var parameters = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n parameters[_i] = arguments[_i];\r\n }\r\n if (!this.cachedPromise) {\r\n this.cachedPromise = _super.prototype.run.apply(this, parameters);\r\n }\r\n return this.cachedPromise;\r\n };\r\n /**\r\n * Run executor without cache. Promise will be put to cache though.\r\n */\r\n CacheExecutor.prototype.runFresh = function () {\r\n var parameters = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n parameters[_i] = arguments[_i];\r\n }\r\n this.cachedPromise = _super.prototype.run.apply(this, parameters);\r\n return this.cachedPromise;\r\n };\r\n /**\r\n * Just clean cache.\r\n */\r\n CacheExecutor.prototype.cleanCache = function () {\r\n this.cachedPromise = null;\r\n };\r\n return CacheExecutor;\r\n}(_Executor__WEBPACK_IMPORTED_MODULE_1__[\"default\"]));\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (CacheExecutor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Executors/CacheExecutor.ts?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Executor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Executor */ \"./src/modules/Executors/Executor.ts\");\nvar __extends = (undefined && undefined.__extends) || (function () {\r\n var extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return function (d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n };\r\n})();\r\n\r\n/**\r\n * This executor caches first run result and provides it for all subsequent calls.\r\n */\r\nvar CacheExecutor = /** @class */ (function (_super) {\r\n __extends(CacheExecutor, _super);\r\n function CacheExecutor() {\r\n var _this = _super !== null && _super.apply(this, arguments) || this;\r\n _this.cachedPromise = null;\r\n return _this;\r\n }\r\n /**\r\n * Run command and cache promise.\r\n */\r\n CacheExecutor.prototype.run = function () {\r\n var parameters = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n parameters[_i] = arguments[_i];\r\n }\r\n if (!this.cachedPromise) {\r\n this.cachedPromise = _super.prototype.run.apply(this, parameters);\r\n }\r\n return this.cachedPromise;\r\n };\r\n /**\r\n * Run executor without cache. Promise will be put to cache though.\r\n */\r\n CacheExecutor.prototype.runFresh = function () {\r\n var parameters = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n parameters[_i] = arguments[_i];\r\n }\r\n this.cachedPromise = _super.prototype.run.apply(this, parameters);\r\n return this.cachedPromise;\r\n };\r\n /**\r\n * Just clean cache.\r\n */\r\n CacheExecutor.prototype.cleanCache = function () {\r\n this.cachedPromise = null;\r\n };\r\n return CacheExecutor;\r\n}(_Executor__WEBPACK_IMPORTED_MODULE_0__[\"default\"]));\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (CacheExecutor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Executors/CacheExecutor.ts?"); | ||
@@ -129,3 +129,3 @@ /***/ }), | ||
"use strict"; | ||
eval("__webpack_require__.r(__webpack_exports__);\n!(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\n/* harmony import */ var _Executor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Executor */ \"./src/modules/Executors/Executor.ts\");\n\r\n\r\n/**\r\n * This executor will chain requests ladder-like.\r\n * Last one will always be executed.\r\n * For skipped requests the promise will never be resolved.\r\n */\r\nvar LadderExecutor = /** @class */ (function (_super) {\r\n !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(LadderExecutor, _super);\r\n function LadderExecutor() {\r\n var _this = _super !== null && _super.apply(this, arguments) || this;\r\n _this.trigger = null;\r\n return _this;\r\n }\r\n LadderExecutor.prototype.run = function () {\r\n var _this = this;\r\n var parameters = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n parameters[_i] = arguments[_i];\r\n }\r\n if (!this.isRunning) {\r\n var promise = _super.prototype.run.apply(this, parameters);\r\n promise.then(function () {\r\n _this.trigger && _this.trigger();\r\n _this.trigger = null;\r\n });\r\n return promise;\r\n }\r\n return new Promise(function (resolve) {\r\n _this.trigger = function () { return _this.run.apply(_this, parameters).then(resolve); };\r\n });\r\n };\r\n return LadderExecutor;\r\n}(_Executor__WEBPACK_IMPORTED_MODULE_1__[\"default\"]));\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (LadderExecutor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Executors/LadderExecutor.ts?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Executor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Executor */ \"./src/modules/Executors/Executor.ts\");\nvar __extends = (undefined && undefined.__extends) || (function () {\r\n var extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r\n return function (d, b) {\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n };\r\n})();\r\n\r\n/**\r\n * This executor will chain requests ladder-like.\r\n * Last one will always be executed.\r\n * For skipped requests the promise will never be resolved.\r\n */\r\nvar LadderExecutor = /** @class */ (function (_super) {\r\n __extends(LadderExecutor, _super);\r\n function LadderExecutor() {\r\n var _this = _super !== null && _super.apply(this, arguments) || this;\r\n _this.trigger = null;\r\n return _this;\r\n }\r\n LadderExecutor.prototype.run = function () {\r\n var _this = this;\r\n var parameters = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n parameters[_i] = arguments[_i];\r\n }\r\n if (!this.isRunning) {\r\n var promise = _super.prototype.run.apply(this, parameters);\r\n promise.then(function () {\r\n _this.trigger && _this.trigger();\r\n _this.trigger = null;\r\n });\r\n return promise;\r\n }\r\n return new Promise(function (resolve) {\r\n _this.trigger = function () { return _this.run.apply(_this, parameters).then(resolve); };\r\n });\r\n };\r\n return LadderExecutor;\r\n}(_Executor__WEBPACK_IMPORTED_MODULE_0__[\"default\"]));\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (LadderExecutor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Executors/LadderExecutor.ts?"); | ||
@@ -166,3 +166,3 @@ /***/ }), | ||
"use strict"; | ||
eval("__webpack_require__.r(__webpack_exports__);\n!(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\n/* harmony import */ var _Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Executors/LadderExecutor */ \"./src/modules/Executors/LadderExecutor.ts\");\n\r\n\r\nvar InfiniteLoader = /** @class */ (function () {\r\n function InfiniteLoader(run, perStep) {\r\n if (perStep === void 0) { perStep = 20; }\r\n this.items = [];\r\n this.isFinished = false;\r\n this.perStep = 20; // number of items to load\r\n this.pointer = 0;\r\n this.isFresh = true;\r\n this.executor = new _Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_1__[\"default\"](run);\r\n this.perStep = perStep;\r\n }\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRunning\", {\r\n /**\r\n * Command from this executor is currently running.\r\n */\r\n get: function () {\r\n return this.executor.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isEmpty\", {\r\n /**\r\n * We tried to load, but list is empty\r\n */\r\n get: function () {\r\n if (this.executor.isRunning) {\r\n return false;\r\n }\r\n return this.isFinished && (this.items.length === 0);\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isFull\", {\r\n /**\r\n * We tried to load, and list is not empty\r\n */\r\n get: function () {\r\n return !!this.items.length;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRefreshing\", {\r\n /**\r\n * Is loading anew. This could happen in two cases.\r\n * 1) Executor is running for the first time. Meaning the list is empty.\r\n * 2) Executor is refreshing. Meaning the list is not empty.\r\n */\r\n get: function () {\r\n return this.pointer === 0 && this.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n /**\r\n * Loads a bunch of items\r\n */\r\n InfiniteLoader.prototype.next = function () {\r\n if (this.isRunning || this.isFinished) {\r\n return;\r\n }\r\n this.isFresh = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.runExecutor = function () {\r\n return !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(this, void 0, void 0, function () {\r\n var result, exception_1;\r\n return !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n _a.trys.push([0, 2, , 3]);\r\n return [4 /*yield*/, this.executor.run(this.pointer, this.perStep)];\r\n case 1:\r\n result = _a.sent();\r\n if (!Array.isArray(result)) {\r\n console.warn('InfiniteLoader function must return array');\r\n return [2 /*return*/];\r\n }\r\n if (result.length < this.perStep) {\r\n this.isFinished = true;\r\n }\r\n this.pointer = this.pointer + this.perStep;\r\n this.applyNew(result);\r\n return [3 /*break*/, 3];\r\n case 2:\r\n exception_1 = _a.sent();\r\n this.isFinished = true;\r\n throw exception_1;\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Refresh the list.\r\n * This will replace current items with new ones after loading. Not clear the list immediately.\r\n */\r\n InfiniteLoader.prototype.refresh = function () {\r\n this.pointer = 0;\r\n this.isFresh = true;\r\n this.isFinished = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.applyNew = function (items) {\r\n if (this.isFresh) {\r\n this.items = items;\r\n return;\r\n }\r\n this.items = this.items.concat(items);\r\n };\r\n return InfiniteLoader;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (InfiniteLoader);\r\n\n\n//# sourceURL=webpack:///./src/modules/Loaders/InfiniteLoader.ts?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Executors/LadderExecutor */ \"./src/modules/Executors/LadderExecutor.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n};\r\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n};\r\n\r\nvar InfiniteLoader = /** @class */ (function () {\r\n function InfiniteLoader(run, perStep) {\r\n if (perStep === void 0) { perStep = 20; }\r\n this.items = [];\r\n this.isFinished = false;\r\n this.perStep = 20; // number of items to load\r\n this.pointer = 0;\r\n this.isFresh = true;\r\n this.executor = new _Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_0__[\"default\"](run);\r\n this.perStep = perStep;\r\n }\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRunning\", {\r\n /**\r\n * Command from this executor is currently running.\r\n */\r\n get: function () {\r\n return this.executor.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isEmpty\", {\r\n /**\r\n * We tried to load, but list is empty\r\n */\r\n get: function () {\r\n if (this.executor.isRunning) {\r\n return false;\r\n }\r\n return this.isFinished && (this.items.length === 0);\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isFull\", {\r\n /**\r\n * We tried to load, and list is not empty\r\n */\r\n get: function () {\r\n return !!this.items.length;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n Object.defineProperty(InfiniteLoader.prototype, \"isRefreshing\", {\r\n /**\r\n * Is loading anew. This could happen in two cases.\r\n * 1) Executor is running for the first time. Meaning the list is empty.\r\n * 2) Executor is refreshing. Meaning the list is not empty.\r\n */\r\n get: function () {\r\n return this.pointer === 0 && this.isRunning;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n /**\r\n * Loads a bunch of items\r\n */\r\n InfiniteLoader.prototype.next = function () {\r\n if (this.isRunning || this.isFinished) {\r\n return;\r\n }\r\n this.isFresh = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.runExecutor = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var result, exception_1;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n _a.trys.push([0, 2, , 3]);\r\n return [4 /*yield*/, this.executor.run(this.pointer, this.perStep)];\r\n case 1:\r\n result = _a.sent();\r\n if (!Array.isArray(result)) {\r\n console.warn('InfiniteLoader function must return array');\r\n return [2 /*return*/];\r\n }\r\n if (result.length < this.perStep) {\r\n this.isFinished = true;\r\n }\r\n this.pointer = this.pointer + this.perStep;\r\n this.applyNew(result);\r\n return [3 /*break*/, 3];\r\n case 2:\r\n exception_1 = _a.sent();\r\n this.isFinished = true;\r\n throw exception_1;\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n /**\r\n * Refresh the list.\r\n * This will replace current items with new ones after loading. Not clear the list immediately.\r\n */\r\n InfiniteLoader.prototype.refresh = function () {\r\n this.pointer = 0;\r\n this.isFresh = true;\r\n this.isFinished = false;\r\n this.runExecutor();\r\n };\r\n InfiniteLoader.prototype.applyNew = function (items) {\r\n if (this.isFresh) {\r\n this.items = items;\r\n return;\r\n }\r\n this.items = this.items.concat(items);\r\n };\r\n return InfiniteLoader;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (InfiniteLoader);\r\n\n\n//# sourceURL=webpack:///./src/modules/Loaders/InfiniteLoader.ts?"); | ||
@@ -215,3 +215,3 @@ /***/ }), | ||
"use strict"; | ||
eval("__webpack_require__.r(__webpack_exports__);\n!(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\n/* harmony import */ var _Helpers_AsyncHelpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../Helpers/AsyncHelpers */ \"./src/modules/Helpers/AsyncHelpers.ts\");\n\r\n\r\nvar RetrierExecutor = /** @class */ (function () {\r\n function RetrierExecutor(command, timeout, maxTime) {\r\n if (timeout === void 0) { timeout = 100; }\r\n if (maxTime === void 0) { maxTime = 1000; }\r\n this.iterationCount = 0;\r\n this.command = command;\r\n this.timeout = timeout;\r\n this.maxTime = maxTime;\r\n }\r\n /**\r\n * Shortcut to use executor functionally.\r\n */\r\n RetrierExecutor.waitUntil = function (command, timeout, maxTime) {\r\n return !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(this, void 0, void 0, function () {\r\n var executor;\r\n return !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n executor = new RetrierExecutor(command, timeout, maxTime);\r\n return [4 /*yield*/, executor.run()];\r\n case 1:\r\n _a.sent();\r\n return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n Object.defineProperty(RetrierExecutor.prototype, \"timeElapsed\", {\r\n get: function () {\r\n return this.timeout * this.iterationCount;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n RetrierExecutor.prototype.takesTooLong = function () {\r\n return this.timeElapsed > this.maxTime;\r\n };\r\n RetrierExecutor.prototype.run = function () {\r\n return !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(this, void 0, void 0, function () {\r\n var result;\r\n return !(function webpackMissingModule() { var e = new Error(\"Cannot find module \\\"tslib\\\"\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n this.iterationCount = 0;\r\n result = this.command();\r\n _a.label = 1;\r\n case 1:\r\n if (!!result) return [3 /*break*/, 3];\r\n return [4 /*yield*/, _Helpers_AsyncHelpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"].sleep(this.timeout)];\r\n case 2:\r\n _a.sent();\r\n this.iterationCount++;\r\n if (this.takesTooLong()) {\r\n throw new Error(\"Max time (\" + this.maxTime + \") elapsed.\");\r\n }\r\n result = this.command();\r\n return [3 /*break*/, 1];\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n return RetrierExecutor;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (RetrierExecutor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Loaders/RetrierExecutor.ts?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Helpers_AsyncHelpers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Helpers/AsyncHelpers */ \"./src/modules/Helpers/AsyncHelpers.ts\");\nvar __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n};\r\nvar __generator = (undefined && undefined.__generator) || function (thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [0, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n};\r\n\r\nvar RetrierExecutor = /** @class */ (function () {\r\n function RetrierExecutor(command, timeout, maxTime) {\r\n if (timeout === void 0) { timeout = 100; }\r\n if (maxTime === void 0) { maxTime = 1000; }\r\n this.iterationCount = 0;\r\n this.command = command;\r\n this.timeout = timeout;\r\n this.maxTime = maxTime;\r\n }\r\n /**\r\n * Shortcut to use executor functionally.\r\n */\r\n RetrierExecutor.waitUntil = function (command, timeout, maxTime) {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var executor;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n executor = new RetrierExecutor(command, timeout, maxTime);\r\n return [4 /*yield*/, executor.run()];\r\n case 1:\r\n _a.sent();\r\n return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n Object.defineProperty(RetrierExecutor.prototype, \"timeElapsed\", {\r\n get: function () {\r\n return this.timeout * this.iterationCount;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n RetrierExecutor.prototype.takesTooLong = function () {\r\n return this.timeElapsed > this.maxTime;\r\n };\r\n RetrierExecutor.prototype.run = function () {\r\n return __awaiter(this, void 0, void 0, function () {\r\n var result;\r\n return __generator(this, function (_a) {\r\n switch (_a.label) {\r\n case 0:\r\n this.iterationCount = 0;\r\n result = this.command();\r\n _a.label = 1;\r\n case 1:\r\n if (!!result) return [3 /*break*/, 3];\r\n return [4 /*yield*/, _Helpers_AsyncHelpers__WEBPACK_IMPORTED_MODULE_0__[\"default\"].sleep(this.timeout)];\r\n case 2:\r\n _a.sent();\r\n this.iterationCount++;\r\n if (this.takesTooLong()) {\r\n throw new Error(\"Max time (\" + this.maxTime + \") elapsed.\");\r\n }\r\n result = this.command();\r\n return [3 /*break*/, 1];\r\n case 3: return [2 /*return*/];\r\n }\r\n });\r\n });\r\n };\r\n return RetrierExecutor;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (RetrierExecutor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Loaders/RetrierExecutor.ts?"); | ||
@@ -218,0 +218,0 @@ /***/ }) |
{ | ||
"name": "asva-executors", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "Helper classes for your async flow control", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -25,3 +25,3 @@ { | ||
// "noEmit": true, /* Do not emit outputs. */ | ||
"importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
@@ -28,0 +28,0 @@ // "isolatedModules": true, \ /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ |
91886
41
1522