ismx-nexo-node-app 0.4.32 → 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.
@@ -1,29 +1,44 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  const Business_1 = __importDefault(require("./Business"));
7
16
  class BusinessThread extends Business_1.default {
8
- constructor() {
17
+ constructor(runImmediately = false) {
9
18
  super();
19
+ this.runImmediately = runImmediately;
10
20
  }
11
21
  init() {
12
- var _a, _b;
13
- this.timeoutId = setTimeout(() => {
14
- this.intervalId = setInterval(() => {
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
+ }
30
+ this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
15
31
  try {
16
- this.run();
32
+ yield this.run();
17
33
  }
18
34
  catch (err) {
19
35
  this.onError(err);
20
36
  }
21
- }, this.interval());
22
- }, (_b = (_a = this.delay) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : 0);
37
+ }), this.interval());
38
+ });
23
39
  }
24
40
  terminate() {
25
41
  clearInterval(this.intervalId);
26
- clearTimeout(this.timeoutId);
27
42
  }
28
43
  onError(err) { }
29
44
  }
@@ -1,11 +1,11 @@
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
- abstract run(): void;
8
+ abstract run(): Promise<void>;
9
9
  abstract interval(): number;
10
10
  abstract delay?(): number;
11
11
  onError(err: Error): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.32",
3
+ "version": "0.4.34",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -2,28 +2,29 @@ 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(() => {
15
- try { 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
- abstract run(): void
27
+ abstract run(): Promise<void>
27
28
  abstract interval(): number
28
29
  abstract delay?(): number
29
30
  onError(err: Error) {}