ismx-nexo-node-app 0.4.33 → 0.4.34

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.
@@ -14,12 +14,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const Business_1 = __importDefault(require("./Business"));
16
16
  class BusinessThread extends Business_1.default {
17
- constructor() {
17
+ constructor(runImmediately = false) {
18
18
  super();
19
+ this.runImmediately = runImmediately;
19
20
  }
20
21
  init() {
21
- var _a, _b;
22
- this.timeoutId = setTimeout(() => {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ if (this.runImmediately)
24
+ try {
25
+ yield this.run();
26
+ }
27
+ catch (err) {
28
+ this.onError(err);
29
+ }
23
30
  this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
24
31
  try {
25
32
  yield this.run();
@@ -28,11 +35,10 @@ class BusinessThread extends Business_1.default {
28
35
  this.onError(err);
29
36
  }
30
37
  }), this.interval());
31
- }, (_b = (_a = this.delay) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : 0);
38
+ });
32
39
  }
33
40
  terminate() {
34
41
  clearInterval(this.intervalId);
35
- clearTimeout(this.timeoutId);
36
42
  }
37
43
  onError(err) { }
38
44
  }
@@ -1,9 +1,9 @@
1
1
  import Business from "./Business";
2
2
  export default abstract class BusinessThread extends Business {
3
+ private runImmediately;
3
4
  private intervalId?;
4
- private timeoutId?;
5
- constructor();
6
- init(): void;
5
+ protected constructor(runImmediately?: boolean);
6
+ init(): Promise<void>;
7
7
  terminate(): void;
8
8
  abstract run(): Promise<void>;
9
9
  abstract interval(): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.33",
3
+ "version": "0.4.34",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -2,25 +2,26 @@ import Business from "./Business";
2
2
 
3
3
  export default abstract class BusinessThread extends Business
4
4
  {
5
+ private runImmediately: boolean;
5
6
  private intervalId?: NodeJS.Timeout;
6
- private timeoutId?: NodeJS.Timeout;
7
7
 
8
- constructor() {
8
+ protected constructor(runImmediately: boolean = false) {
9
9
  super();
10
+ this.runImmediately = runImmediately;
10
11
  }
11
12
 
12
- init() {
13
- this.timeoutId = setTimeout(() => {
14
- this.intervalId = setInterval(async () => {
15
- try { await this.run() }
16
- catch (err) { this.onError(err as Error) }
17
- }, this.interval());
18
- }, this.delay?.() ?? 0);
13
+ async init() {
14
+
15
+ if (this.runImmediately)
16
+ try { await this.run() } catch (err) { this.onError(err as Error) }
17
+
18
+ this.intervalId = setInterval(async () => {
19
+ try { await this.run() } catch (err) { this.onError(err as Error) }
20
+ }, this.interval());
19
21
  }
20
22
 
21
23
  terminate() {
22
24
  clearInterval(this.intervalId);
23
- clearTimeout(this.timeoutId);
24
25
  }
25
26
 
26
27
  abstract run(): Promise<void>