@dra2020/baseclient 1.0.174 → 1.0.175
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/baseclient.js +37 -1
- package/dist/baseclient.js.map +1 -1
- package/dist/fsm/fsm.d.ts +5 -0
- package/lib/fsm/fsm.ts +47 -1
- package/package.json +1 -1
package/dist/fsm/fsm.d.ts
CHANGED
|
@@ -15,15 +15,19 @@ export declare const FSM_CUSTOM7: number;
|
|
|
15
15
|
export declare const FSM_CUSTOM8: number;
|
|
16
16
|
export declare const FSM_CUSTOM9: number;
|
|
17
17
|
export type FsmIndex = Set<Fsm>;
|
|
18
|
+
export type FsmExceptionHandler = (fsm: Fsm, err: any) => void;
|
|
18
19
|
export declare class FsmManager {
|
|
19
20
|
theId: number;
|
|
20
21
|
theEpoch: number;
|
|
21
22
|
bTickSet: boolean;
|
|
22
23
|
theTickList: FsmIndex;
|
|
23
24
|
theBusyLoopCount: number;
|
|
25
|
+
theExceptionCount: number;
|
|
26
|
+
onException: FsmExceptionHandler;
|
|
24
27
|
constructor();
|
|
25
28
|
forceTick(fsm: Fsm): void;
|
|
26
29
|
doTick(): void;
|
|
30
|
+
tickException(f: Fsm, err: any): void;
|
|
27
31
|
}
|
|
28
32
|
export interface FsmEnvironment {
|
|
29
33
|
fsmManager: FsmManager;
|
|
@@ -55,6 +59,7 @@ export declare class Fsm {
|
|
|
55
59
|
waitOnCompleted(f: Fsm): void;
|
|
56
60
|
_completed(f: Fsm): void;
|
|
57
61
|
tick(): void;
|
|
62
|
+
tickException(err: any): void;
|
|
58
63
|
}
|
|
59
64
|
export declare class FsmOnDone extends Fsm {
|
|
60
65
|
cb: any;
|
package/lib/fsm/fsm.ts
CHANGED
|
@@ -53,6 +53,8 @@ function FsmStateToString(state: number): string
|
|
|
53
53
|
|
|
54
54
|
export type FsmIndex = Set<Fsm>;
|
|
55
55
|
|
|
56
|
+
export type FsmExceptionHandler = (fsm: Fsm, err: any) => void;
|
|
57
|
+
|
|
56
58
|
export class FsmManager
|
|
57
59
|
{
|
|
58
60
|
theId: number;
|
|
@@ -60,6 +62,8 @@ export class FsmManager
|
|
|
60
62
|
bTickSet: boolean;
|
|
61
63
|
theTickList: FsmIndex;
|
|
62
64
|
theBusyLoopCount: number;
|
|
65
|
+
theExceptionCount: number;
|
|
66
|
+
onException: FsmExceptionHandler;
|
|
63
67
|
|
|
64
68
|
constructor()
|
|
65
69
|
{
|
|
@@ -68,6 +72,8 @@ export class FsmManager
|
|
|
68
72
|
this.bTickSet = false;
|
|
69
73
|
this.theTickList = new Set<Fsm>();
|
|
70
74
|
this.theBusyLoopCount = 0;
|
|
75
|
+
this.theExceptionCount = 0;
|
|
76
|
+
this.onException = (fsm: Fsm, err: any) => { console.error(`Fsm(${fsm.constructor.name}): exception in tick:`, err) };
|
|
71
77
|
this.doTick = this.doTick.bind(this);
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -92,7 +98,16 @@ export class FsmManager
|
|
|
92
98
|
let thisTickList = this.theTickList;
|
|
93
99
|
this.theTickList = new Set<Fsm>();
|
|
94
100
|
|
|
95
|
-
thisTickList.forEach((f: Fsm) =>
|
|
101
|
+
thisTickList.forEach((f: Fsm) => {
|
|
102
|
+
try
|
|
103
|
+
{
|
|
104
|
+
f.tick();
|
|
105
|
+
}
|
|
106
|
+
catch (err)
|
|
107
|
+
{
|
|
108
|
+
this.tickException(f, err);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
if (this.theTickList.size == 0)
|
|
@@ -102,6 +117,29 @@ export class FsmManager
|
|
|
102
117
|
|
|
103
118
|
this.theEpoch++;
|
|
104
119
|
}
|
|
120
|
+
|
|
121
|
+
// An exception escaping a tick would otherwise unwind out of setImmediate and take down the whole
|
|
122
|
+
// process (or, in the browser, leave the tick loop wedged). Instead, report it and let the Fsm
|
|
123
|
+
// fail itself so anything waiting on it sees a dependent error rather than hanging forever.
|
|
124
|
+
tickException(f: Fsm, err: any): void
|
|
125
|
+
{
|
|
126
|
+
this.theExceptionCount++;
|
|
127
|
+
try
|
|
128
|
+
{
|
|
129
|
+
this.onException(f, err);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {}
|
|
132
|
+
try
|
|
133
|
+
{
|
|
134
|
+
f.tickException(err);
|
|
135
|
+
}
|
|
136
|
+
catch (e)
|
|
137
|
+
{
|
|
138
|
+
try { this.onException(f, e) } catch (e2) {}
|
|
139
|
+
if (! f.done)
|
|
140
|
+
f.setState(FSM_ERROR);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
105
143
|
}
|
|
106
144
|
|
|
107
145
|
export interface FsmEnvironment
|
|
@@ -225,6 +263,14 @@ export class Fsm
|
|
|
225
263
|
tick(): void
|
|
226
264
|
{
|
|
227
265
|
}
|
|
266
|
+
|
|
267
|
+
// Called (after FsmManager.onException has reported it) when tick() throws. Override to clean up or
|
|
268
|
+
// respond, but make sure the Fsm ends up done.
|
|
269
|
+
tickException(err: any): void
|
|
270
|
+
{
|
|
271
|
+
if (! this.done)
|
|
272
|
+
this.setState(FSM_ERROR);
|
|
273
|
+
}
|
|
228
274
|
}
|
|
229
275
|
|
|
230
276
|
// Launches callback provided when the associated Fsm (or Fsm array) completes.
|