asva-executors
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -1,8 +0,5 @@ | ||
import _CacheExecutor from './modules/Executors/CacheExecutor'; | ||
import _Executor from './modules/Executors/Executor'; | ||
import _LadderExecutor from './modules/Executors/LadderExecutor'; | ||
import _RepeatExecutor from './modules/Executors/RepeatExecutor'; | ||
export declare const CacheExecutor: typeof _CacheExecutor; | ||
export declare const Executor: typeof _Executor; | ||
export declare const LadderExecutor: typeof _LadderExecutor; | ||
export declare const RepeatExecutor: typeof _RepeatExecutor; | ||
import CacheExecutor from './modules/Executors/CacheExecutor'; | ||
import Executor from './modules/Executors/Executor'; | ||
import LadderExecutor from './modules/Executors/LadderExecutor'; | ||
import RepeatExecutor from './modules/Executors/RepeatExecutor'; | ||
export { CacheExecutor, Executor, LadderExecutor, RepeatExecutor }; |
@@ -82,3 +82,3 @@ /******/ (function(modules) { // webpackBootstrap | ||
"use strict"; | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CacheExecutor\", function() { return CacheExecutor; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Executor\", function() { return Executor; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"LadderExecutor\", function() { return LadderExecutor; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"RepeatExecutor\", function() { return RepeatExecutor; });\n/* harmony import */ var _modules_Executors_CacheExecutor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modules/Executors/CacheExecutor */ \"./src/modules/Executors/CacheExecutor.ts\");\n/* harmony import */ var _modules_Executors_Executor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modules/Executors/Executor */ \"./src/modules/Executors/Executor.ts\");\n/* harmony import */ var _modules_Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modules/Executors/LadderExecutor */ \"./src/modules/Executors/LadderExecutor.ts\");\n/* harmony import */ var _modules_Executors_RepeatExecutor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./modules/Executors/RepeatExecutor */ \"./src/modules/Executors/RepeatExecutor.ts\");\n\r\n\r\n\r\n\r\nvar CacheExecutor = _modules_Executors_CacheExecutor__WEBPACK_IMPORTED_MODULE_0__[\"default\"];\r\nvar Executor = _modules_Executors_Executor__WEBPACK_IMPORTED_MODULE_1__[\"default\"];\r\nvar LadderExecutor = _modules_Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_2__[\"default\"];\r\nvar RepeatExecutor = _modules_Executors_RepeatExecutor__WEBPACK_IMPORTED_MODULE_3__[\"default\"];\r\n\n\n//# sourceURL=webpack:///./src/index.ts?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _modules_Executors_CacheExecutor__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./modules/Executors/CacheExecutor */ \"./src/modules/Executors/CacheExecutor.ts\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"CacheExecutor\", function() { return _modules_Executors_CacheExecutor__WEBPACK_IMPORTED_MODULE_0__[\"default\"]; });\n\n/* harmony import */ var _modules_Executors_Executor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./modules/Executors/Executor */ \"./src/modules/Executors/Executor.ts\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"Executor\", function() { return _modules_Executors_Executor__WEBPACK_IMPORTED_MODULE_1__[\"default\"]; });\n\n/* harmony import */ var _modules_Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./modules/Executors/LadderExecutor */ \"./src/modules/Executors/LadderExecutor.ts\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"LadderExecutor\", function() { return _modules_Executors_LadderExecutor__WEBPACK_IMPORTED_MODULE_2__[\"default\"]; });\n\n/* harmony import */ var _modules_Executors_RepeatExecutor__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./modules/Executors/RepeatExecutor */ \"./src/modules/Executors/RepeatExecutor.ts\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"RepeatExecutor\", function() { return _modules_Executors_RepeatExecutor__WEBPACK_IMPORTED_MODULE_3__[\"default\"]; });\n\n\r\n\r\n\r\n\r\n\r\n\n\n//# sourceURL=webpack:///./src/index.ts?"); | ||
@@ -107,3 +107,3 @@ /***/ }), | ||
"use strict"; | ||
eval("__webpack_require__.r(__webpack_exports__);\nvar Executor = /** @class */ (function () {\r\n function Executor(command) {\r\n this.wasLastRunFine = false;\r\n this.runCount = 0; // Currently active commands count\r\n this.wasRun = false;\r\n this.wasRunFine = false;\r\n this.wasRunBad = false;\r\n this.command = command;\r\n }\r\n Object.defineProperty(Executor.prototype, \"isRunning\", {\r\n get: function () {\r\n return !!this.runCount;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n /**\r\n * @protected\r\n */\r\n Executor.prototype.beforeRun = function () {\r\n this.runCount++;\r\n };\r\n /**\r\n * @protected\r\n */\r\n Executor.prototype.afterRun = function (promise) {\r\n var _this = this;\r\n promise.then(function () {\r\n _this.runCount--;\r\n _this.setRunResultFlags(true);\r\n });\r\n promise.catch(function (result) {\r\n _this.runCount--;\r\n _this.setRunResultFlags(false);\r\n });\r\n };\r\n /**\r\n * @public\r\n */\r\n Executor.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 this.beforeRun();\r\n var promise = this.command.apply(this, parameters);\r\n if (!(promise instanceof Promise)) {\r\n throw new Error('Executor command should return promise.');\r\n }\r\n this.afterRun(promise);\r\n return promise;\r\n };\r\n /**\r\n * @protected\r\n */\r\n Executor.prototype.setRunResultFlags = function (success) {\r\n this.wasRun = true;\r\n this.wasLastRunFine = success;\r\n if (success) {\r\n this.wasRunFine = true;\r\n }\r\n if (!success) {\r\n this.wasRunBad = true;\r\n }\r\n };\r\n return Executor;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (Executor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Executors/Executor.ts?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\nvar Executor = /** @class */ (function () {\r\n function Executor(command) {\r\n this.wasLastRunFine = false; //\r\n this.runCount = 0; // Currently active commands count\r\n this.wasRun = false; // Executor was run at least once\r\n this.wasRunFine = false; // Executor was without throwing error at least once\r\n this.wasRunBad = false; //\r\n this.command = command;\r\n }\r\n Object.defineProperty(Executor.prototype, \"isRunning\", {\r\n get: function () {\r\n return !!this.runCount;\r\n },\r\n enumerable: true,\r\n configurable: true\r\n });\r\n /**\r\n * @protected\r\n */\r\n Executor.prototype.beforeRun = function () {\r\n this.runCount++;\r\n };\r\n /**\r\n * @protected\r\n */\r\n Executor.prototype.afterRun = function (promise) {\r\n var _this = this;\r\n promise.then(function () {\r\n _this.runCount--;\r\n _this.setRunResultFlags(true);\r\n });\r\n promise.catch(function (result) {\r\n _this.runCount--;\r\n _this.setRunResultFlags(false);\r\n });\r\n };\r\n /**\r\n * @public\r\n */\r\n Executor.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 this.beforeRun();\r\n var promise = this.command.apply(this, parameters);\r\n if (!(promise instanceof Promise)) {\r\n throw new Error('Executor command should return promise.');\r\n }\r\n this.afterRun(promise);\r\n return promise;\r\n };\r\n /**\r\n * @protected\r\n */\r\n Executor.prototype.setRunResultFlags = function (success) {\r\n this.wasRun = true;\r\n this.wasLastRunFine = success;\r\n if (success) {\r\n this.wasRunFine = true;\r\n }\r\n if (!success) {\r\n this.wasRunBad = true;\r\n }\r\n };\r\n return Executor;\r\n}());\r\n/* harmony default export */ __webpack_exports__[\"default\"] = (Executor);\r\n\n\n//# sourceURL=webpack:///./src/modules/Executors/Executor.ts?"); | ||
@@ -110,0 +110,0 @@ /***/ }), |
export default class Executor { | ||
command: Function; | ||
protected command: Function; | ||
wasLastRunFine: boolean; | ||
@@ -4,0 +4,0 @@ runCount: number; |
{ | ||
"name": "asva-executors", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Helper classes for your async flow control", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -10,2 +10,27 @@ # asva-executors | ||
## Api | ||
To import class use: | ||
```javascript | ||
import { Executor } from 'asva-executors' | ||
``` | ||
The library provides you with the following classes: | ||
### Executor | ||
#### Props | ||
Chances are, the only prop you'll use is `isRunning` | ||
* isRunning - | ||
* wasLastRunFine - | ||
* runCount - | ||
* wasRun - | ||
* wasRunFine - | ||
* wasRunBad - | ||
```javascript | ||
import { Executor } from 'asva-executors' | ||
``` | ||
## Issues | ||
@@ -12,0 +37,0 @@ |
@@ -1,9 +0,11 @@ | ||
import _CacheExecutor from './modules/Executors/CacheExecutor' | ||
import _Executor from './modules/Executors/Executor' | ||
import _LadderExecutor from './modules/Executors/LadderExecutor' | ||
import _RepeatExecutor from './modules/Executors/RepeatExecutor' | ||
import CacheExecutor from './modules/Executors/CacheExecutor' | ||
import Executor from './modules/Executors/Executor' | ||
import LadderExecutor from './modules/Executors/LadderExecutor' | ||
import RepeatExecutor from './modules/Executors/RepeatExecutor' | ||
export const CacheExecutor = _CacheExecutor | ||
export const Executor = _Executor | ||
export const LadderExecutor = _LadderExecutor | ||
export const RepeatExecutor = _RepeatExecutor | ||
export { | ||
CacheExecutor, | ||
Executor, | ||
LadderExecutor, | ||
RepeatExecutor, | ||
} |
export default class Executor { | ||
command: Function | ||
wasLastRunFine: boolean = false | ||
protected command: Function | ||
wasLastRunFine: boolean = false // | ||
runCount: number = 0 // Currently active commands count | ||
wasRun: boolean = false | ||
wasRunFine: boolean = false | ||
wasRunBad: boolean = false | ||
wasRun: boolean = false // Executor was run at least once | ||
wasRunFine: boolean = false // Executor was without throwing error at least once | ||
wasRunBad: boolean = false // | ||
constructor (command: (...args: any[]) => Promise<any> ) { | ||
constructor (command: (...args: any[]) => Promise<any>) { | ||
this.command = command | ||
@@ -27,3 +28,3 @@ } | ||
*/ | ||
afterRun (promise: Promise<any> ): void { | ||
afterRun (promise: Promise<any>): void { | ||
promise.then(() => { | ||
@@ -42,3 +43,3 @@ this.runCount-- | ||
*/ | ||
run (...parameters: any[]): Promise<any> { | ||
run (...parameters: any[]): Promise<any> { | ||
this.beforeRun() | ||
@@ -45,0 +46,0 @@ const promise = this.command(...parameters) |
36130
41
750