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.
- package/dist/js/business/utils/PromiseUtils.js +25 -0
- package/dist/types/business/BusinessState.d.ts +1 -1
- package/dist/types/business/utils/PromiseUtils.d.ts +7 -0
- package/package.json +1 -1
- package/src/main/node/business/BusinessState.ts +1 -1
- package/src/main/node/business/utils/PromiseUtils.ts +33 -0
|
@@ -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
|
-
|
|
10
|
+
remove(id: string): void;
|
|
11
11
|
protected notify(data?: Model): void;
|
|
12
12
|
protected clone(data: Model): Model;
|
|
13
13
|
private reviver;
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|