ismx-nexo-node-app 0.4.128 → 0.4.129

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.
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PromiseUtils {
4
+ static tokenize(promise) {
5
+ let cancelled = false;
6
+ let onCancelledCb;
7
+ let rejectOuter;
8
+ const cancel = (onCancelled) => {
9
+ onCancelledCb = onCancelled;
10
+ return token;
11
+ };
12
+ const stop = () => {
13
+ cancelled = true;
14
+ onCancelledCb === null || onCancelledCb === void 0 ? void 0 : onCancelledCb();
15
+ };
16
+ const wrapped = new Promise((resolve, reject) => {
17
+ promise.then(value => { if (!cancelled)
18
+ resolve(value); }, error => { if (!cancelled)
19
+ reject(error); });
20
+ });
21
+ const token = Object.assign(wrapped, { stop, cancel });
22
+ return token;
23
+ }
24
+ }
25
+ exports.default = PromiseUtils;
@@ -7,7 +7,7 @@ export default class BusinessState<Model> {
7
7
  init(): Promise<void>;
8
8
  observe(listener: (data: Model) => any, runOnObserve?: boolean): string;
9
9
  observeId(id: string, listener: (data: Model) => any, runOnObserve?: boolean): string;
10
- protected remove(id: string): void;
10
+ remove(id: string): void;
11
11
  protected notify(data?: Model): void;
12
12
  protected clone(data: Model): Model;
13
13
  private reviver;
@@ -0,0 +1,7 @@
1
+ export interface Token<T> extends Promise<T> {
2
+ stop: () => void;
3
+ cancel(onCancelled: () => void): this;
4
+ }
5
+ export default abstract class PromiseUtils {
6
+ static tokenize<T>(promise: Promise<T>): Token<T>;
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.128",
3
+ "version": "0.4.129",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -20,7 +20,7 @@ export default class BusinessState<Model>
20
20
  return id;
21
21
  }
22
22
 
23
- protected remove(id: string) {
23
+ remove(id: string) {
24
24
  delete this.listeners[id];
25
25
  }
26
26
 
@@ -0,0 +1,33 @@
1
+ export interface Token<T> extends Promise<T> {
2
+ stop: () => void;
3
+ cancel(onCancelled: () => void): this;
4
+ }
5
+
6
+ export default abstract class PromiseUtils {
7
+
8
+ public static tokenize<T>(promise: Promise<T>): Token<T>
9
+ {
10
+ let cancelled = false;
11
+ let onCancelledCb: (() => void) | undefined;
12
+ let rejectOuter: ((reason?: any) => void) | undefined;
13
+
14
+ const cancel = (onCancelled: () => void) => {
15
+ onCancelledCb = onCancelled; return token;
16
+ };
17
+
18
+ const stop = () => {
19
+ cancelled = true; onCancelledCb?.();
20
+ };
21
+
22
+ const wrapped = new Promise<T>((resolve, reject) => {
23
+ promise.then(
24
+ value => { if (!cancelled) resolve(value); },
25
+ error => { if (!cancelled) reject(error); }
26
+ );
27
+ });
28
+
29
+ const token: Token<T> = Object.assign(wrapped, { stop, cancel });
30
+ return token;
31
+ }
32
+
33
+ }