@statewalker/fsm 0.23.0 → 0.24.0

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/index.d.ts CHANGED
@@ -6,6 +6,7 @@ declare class FsmBaseClass {
6
6
  getData<T>(key: string): T | undefined;
7
7
  _addHandler(type: string, handler: Function, direct?: boolean): () => void;
8
8
  _removeHandler(type: string, handler: Function): void;
9
+ _runHandlerParallel(type: string, ...args: unknown[]): Promise<void>;
9
10
  _runHandler(type: string, ...args: unknown[]): Promise<void>;
10
11
  _handleError(error: Error | unknown): Promise<void>;
11
12
  }
@@ -71,12 +72,15 @@ type FsmProcessDumpHandler = (process: FsmProcess, dump: FsmProcessDump) => void
71
72
  declare class FsmProcess extends FsmBaseClass {
72
73
  state?: FsmState;
73
74
  event?: string;
75
+ nextEvent?: string;
76
+ running: boolean;
77
+ mask: number;
74
78
  status: number;
75
79
  config: FsmStateConfig;
76
80
  rootDescriptor: FsmStateDescriptor;
77
81
  constructor(config: FsmStateConfig);
78
82
  shutdown(event?: string): Promise<void>;
79
- dispatch(event: string, mask?: number): Promise<boolean>;
83
+ dispatch(event: string): Promise<boolean>;
80
84
  dump(...args: unknown[]): Promise<FsmProcessDump>;
81
85
  restore(dump: FsmProcessDump, ...args: unknown[]): Promise<this>;
82
86
  onStateCreate(handler: FsmStateHandler): () => void;
@@ -88,4 +92,29 @@ declare class FsmProcess extends FsmBaseClass {
88
92
  _update(): boolean;
89
93
  }
90
94
 
91
- export { EVENT_ANY, EVENT_EMPTY, type FsmEventKey, FsmProcess, type FsmProcessDump, type FsmProcessDumpHandler, type FsmProcessHandler, FsmState, type FsmStateConfig, FsmStateDescriptor, type FsmStateDump, type FsmStateDumpHandler, type FsmStateErrorHandler, type FsmStateHandler, type FsmStateKey, STATE_ANY, STATE_FINAL, STATE_INITIAL, STATUS_ENTER, STATUS_EXIT, STATUS_FINISHED, STATUS_FIRST, STATUS_LAST, STATUS_LEAF, STATUS_NEXT, STATUS_NONE };
95
+ type Printer = (...args: unknown[]) => void;
96
+ type PrinterConfig = {
97
+ prefix?: string;
98
+ print?: (...args: unknown[]) => void;
99
+ lineNumbers?: boolean;
100
+ };
101
+ declare const KEY_PRINTER = "printer";
102
+ declare function preparePrinter(process: FsmProcess, { prefix, print, lineNumbers }: PrinterConfig): Printer;
103
+ declare function setPrinter(state: FsmState, config?: PrinterConfig): void;
104
+ declare function setProcessPrinter(process: FsmProcess, config?: PrinterConfig): void;
105
+ declare function getProcessPrinter(process: FsmProcess): Printer;
106
+ declare function getPrinter(state: FsmState): Printer;
107
+
108
+ declare function newProcess(config: FsmStateConfig, { prefix, print, lineNumbers, }: {
109
+ prefix?: string;
110
+ print?: (...args: any[]) => void;
111
+ lineNumbers?: boolean;
112
+ }): FsmProcess;
113
+
114
+ declare function setProcessTracer(process: FsmProcess, print?: Printer): () => void;
115
+ declare function setStateTracer(state: FsmState, print?: Printer): void;
116
+
117
+ declare function isStateTransitionEnabled(process: FsmProcess, event: string): boolean;
118
+ declare function getStateTransitions(state?: FsmState): [from: string, event: string, to: string][];
119
+
120
+ export { EVENT_ANY, EVENT_EMPTY, type FsmEventKey, FsmProcess, type FsmProcessDump, type FsmProcessDumpHandler, type FsmProcessHandler, FsmState, type FsmStateConfig, FsmStateDescriptor, type FsmStateDump, type FsmStateDumpHandler, type FsmStateErrorHandler, type FsmStateHandler, type FsmStateKey, KEY_PRINTER, type Printer, type PrinterConfig, STATE_ANY, STATE_FINAL, STATE_INITIAL, STATUS_ENTER, STATUS_EXIT, STATUS_FINISHED, STATUS_FIRST, STATUS_LAST, STATUS_LEAF, STATUS_NEXT, STATUS_NONE, getPrinter, getProcessPrinter, getStateTransitions, isStateTransitionEnabled, newProcess, preparePrinter, setPrinter, setProcessPrinter, setProcessTracer, setStateTracer };
package/dist/index.js CHANGED
@@ -1,27 +1,420 @@
1
- import {
2
- EVENT_ANY,
3
- EVENT_EMPTY,
4
- FsmProcess,
5
- FsmState,
6
- FsmStateDescriptor,
7
- STATE_ANY,
8
- STATE_FINAL,
9
- STATE_INITIAL,
10
- STATUS_ENTER,
11
- STATUS_EXIT,
12
- STATUS_FINISHED,
13
- STATUS_FIRST,
14
- STATUS_LAST,
15
- STATUS_LEAF,
16
- STATUS_NEXT,
17
- STATUS_NONE
18
- } from "./chunk-CRID7TZR.js";
1
+ // src/FsmBaseClass.ts
2
+ var FsmBaseClass = class {
3
+ constructor() {
4
+ this.handlers = {};
5
+ this.data = {};
6
+ bindMethods(this, "setData", "getData");
7
+ }
8
+ setData(key, value) {
9
+ this.data[key] = value;
10
+ return this;
11
+ }
12
+ getData(key) {
13
+ return this.data[key];
14
+ }
15
+ // ----------------------------------------------
16
+ // internal methods
17
+ _addHandler(type, handler, direct = true) {
18
+ const list = this.handlers[type] = this.handlers[type] || [];
19
+ direct ? list.push(handler) : list.unshift(handler);
20
+ return () => this._removeHandler(type, handler);
21
+ }
22
+ _removeHandler(type, handler) {
23
+ let list = this.handlers[type];
24
+ if (!list) return;
25
+ list = list.filter((h) => h !== handler);
26
+ if (list.length > 0) {
27
+ this.handlers[type] = list;
28
+ } else {
29
+ delete this.handlers[type];
30
+ }
31
+ }
32
+ async _runHandlerParallel(type, ...args) {
33
+ const list = this.handlers[type] || [];
34
+ await Promise.all(
35
+ list.map(async (handler) => {
36
+ try {
37
+ await handler(...args);
38
+ } catch (error) {
39
+ this._handleError(error);
40
+ }
41
+ })
42
+ );
43
+ }
44
+ async _runHandler(type, ...args) {
45
+ const list = this.handlers[type] || [];
46
+ for (const handler of list) {
47
+ try {
48
+ await handler(...args);
49
+ } catch (error) {
50
+ await this._handleError(error);
51
+ }
52
+ }
53
+ }
54
+ async _handleError(error) {
55
+ console.error(error);
56
+ }
57
+ };
58
+ function bindMethods(obj, ...methods) {
59
+ const o = obj;
60
+ for (const methodName of methods) {
61
+ const method = o[methodName];
62
+ if (typeof method !== "function") continue;
63
+ o[methodName] = method.bind(o);
64
+ }
65
+ return obj;
66
+ }
67
+
68
+ // src/FsmState.ts
69
+ var FsmState = class extends FsmBaseClass {
70
+ constructor(process, parent, key, descriptor) {
71
+ super();
72
+ this.process = process;
73
+ this.key = key;
74
+ this.parent = parent;
75
+ this.descriptor = descriptor;
76
+ bindMethods(
77
+ this,
78
+ "onEnter",
79
+ "onExit",
80
+ "dump",
81
+ "restore",
82
+ "useData",
83
+ "onStateError"
84
+ );
85
+ }
86
+ onEnter(handler) {
87
+ return this._addHandler("onEnter", handler, true);
88
+ }
89
+ onExit(handler) {
90
+ return this._addHandler("onExit", handler, false);
91
+ }
92
+ onStateError(handler) {
93
+ return this._addHandler("onStateError", handler);
94
+ }
95
+ dump(handler) {
96
+ return this._addHandler("dump", handler, true);
97
+ }
98
+ restore(handler) {
99
+ return this._addHandler("restore", handler, true);
100
+ }
101
+ getData(key, recursive = true) {
102
+ return this.data[key] ?? (recursive ? this.parent?.getData(key, recursive) : void 0);
103
+ }
104
+ useData(key) {
105
+ return [
106
+ (recursive = true) => this.getData(key, recursive),
107
+ (value) => this.setData(key, value)
108
+ ];
109
+ }
110
+ async _handleError(error) {
111
+ await this._runHandler("onStateError", this, error);
112
+ await this.process._handleStateError(this, error);
113
+ }
114
+ };
115
+
116
+ // src/FsmStateConfig.ts
117
+ var STATE_ANY = "*";
118
+ var STATE_INITIAL = "";
119
+ var STATE_FINAL = "";
120
+ var EVENT_ANY = "*";
121
+ var EVENT_EMPTY = "";
122
+
123
+ // src/FsmStateDescriptor.ts
124
+ var FsmStateDescriptor = class _FsmStateDescriptor {
125
+ constructor() {
126
+ this.transitions = {};
127
+ this.states = {};
128
+ }
129
+ static build(config) {
130
+ const descriptor = new _FsmStateDescriptor();
131
+ for (const [from, event, to] of config.transitions || []) {
132
+ const index = descriptor.transitions[from] = descriptor.transitions[from] || {};
133
+ index[event] = to;
134
+ }
135
+ if (config.states) {
136
+ for (const substateConfig of config.states) {
137
+ descriptor.states[substateConfig.key] = this.build(substateConfig);
138
+ }
139
+ }
140
+ return descriptor;
141
+ }
142
+ getTargetStateKey(stateKey, eventKey) {
143
+ const pairs = [
144
+ [stateKey, eventKey],
145
+ [STATE_ANY, eventKey],
146
+ [stateKey, EVENT_ANY],
147
+ [STATE_ANY, EVENT_ANY]
148
+ ];
149
+ let targetKey;
150
+ for (let i = 0, len = pairs.length; targetKey === void 0 && i < len; i++) {
151
+ const [stateKey2, eventKey2] = pairs[i];
152
+ const stateTransitions = this.transitions[stateKey2];
153
+ if (!stateTransitions) continue;
154
+ targetKey = stateTransitions[eventKey2];
155
+ }
156
+ return targetKey !== void 0 ? targetKey : STATE_FINAL;
157
+ }
158
+ };
159
+
160
+ // src/FsmProcess.ts
161
+ var STATUS_NONE = 0;
162
+ var STATUS_FIRST = 1;
163
+ var STATUS_NEXT = 2;
164
+ var STATUS_LEAF = 4;
165
+ var STATUS_LAST = 8;
166
+ var STATUS_FINISHED = 16;
167
+ var STATUS_ENTER = STATUS_FIRST | STATUS_NEXT;
168
+ var STATUS_EXIT = STATUS_LEAF | STATUS_LAST;
169
+ var FsmProcess = class extends FsmBaseClass {
170
+ constructor(config) {
171
+ super();
172
+ this.running = false;
173
+ this.mask = STATUS_LEAF;
174
+ this.status = 0;
175
+ this.rootDescriptor = FsmStateDescriptor.build(config);
176
+ this.config = config;
177
+ bindMethods(this, "dispatch", "dump", "restore");
178
+ }
179
+ async shutdown(event) {
180
+ while (this.state) {
181
+ this.event = event;
182
+ this.status = STATUS_FINISHED;
183
+ await this.state?._runHandler("onExit", this.state);
184
+ this.state = this.state.parent;
185
+ }
186
+ }
187
+ async dispatch(event) {
188
+ this.nextEvent = event;
189
+ if (!this.running && !(this.status & STATUS_FINISHED)) {
190
+ this.running = true;
191
+ try {
192
+ this.event = this.nextEvent;
193
+ this.nextEvent = void 0;
194
+ while (true) {
195
+ if (this.status & STATUS_EXIT) {
196
+ await this.state?._runHandler("onExit", this.state);
197
+ }
198
+ if (!this._update()) break;
199
+ if (this.status & STATUS_ENTER) {
200
+ await this.state?._runHandler("onEnter", this.state);
201
+ }
202
+ if (this.status & this.mask) break;
203
+ }
204
+ } finally {
205
+ this.running = false;
206
+ }
207
+ if (this.nextEvent !== void 0) {
208
+ await new Promise((r) => setImmediate(r));
209
+ return this.dispatch(this.nextEvent);
210
+ }
211
+ }
212
+ return !(this.status & STATUS_FINISHED);
213
+ }
214
+ async dump(...args) {
215
+ const dumpState = async (state) => {
216
+ const stateDump = {
217
+ key: state.key,
218
+ data: {}
219
+ };
220
+ await state._runHandler("dump", state, stateDump.data, ...args);
221
+ return stateDump;
222
+ };
223
+ const dumpStates = async (state, stack = []) => {
224
+ if (!state) return stack;
225
+ state.parent && await dumpStates(state.parent, stack);
226
+ stack.push(await dumpState(state));
227
+ return stack;
228
+ };
229
+ const dump = {
230
+ status: this.status,
231
+ event: this.event,
232
+ stack: await dumpStates(this.state)
233
+ };
234
+ return dump;
235
+ }
236
+ async restore(dump, ...args) {
237
+ this.status = dump.status || 0;
238
+ this.event = dump.event;
239
+ this.state = void 0;
240
+ for (let i = 0; i < dump.stack.length; i++) {
241
+ const stateDump = dump.stack[i];
242
+ this.state = this.state ? this._newSubstate(this.state, stateDump.key) : this._newState(void 0, stateDump.key, this.rootDescriptor);
243
+ await this.state._runHandler(
244
+ "restore",
245
+ this.state,
246
+ stateDump.data,
247
+ ...args
248
+ );
249
+ }
250
+ return this;
251
+ }
252
+ onStateCreate(handler) {
253
+ return this._addHandler("onStateCreate", handler, true);
254
+ }
255
+ onStateError(handler) {
256
+ return this._addHandler("onStateError", handler);
257
+ }
258
+ async _handleStateError(state, error) {
259
+ await this._runHandler("onStateError", state, error);
260
+ this._handleError(error);
261
+ }
262
+ _newState(parent, key, descriptor) {
263
+ const state = new FsmState(this, parent, key, descriptor);
264
+ this._runHandlerParallel("onStateCreate", state);
265
+ return state;
266
+ }
267
+ _getSubstate(parent, prevStateKey) {
268
+ if (!parent) return;
269
+ const toState = parent.descriptor?.getTargetStateKey(
270
+ prevStateKey || STATE_INITIAL,
271
+ this.event || EVENT_EMPTY
272
+ ) || STATE_FINAL;
273
+ if (!toState) return;
274
+ return this._newSubstate(parent, toState);
275
+ }
276
+ _newSubstate(parent, toState) {
277
+ let descriptor;
278
+ for (let state = parent; !descriptor && state; state = state.parent) {
279
+ descriptor = state.descriptor?.states[toState];
280
+ }
281
+ return this._newState(parent, toState, descriptor);
282
+ }
283
+ _update() {
284
+ if (this.status & STATUS_FINISHED) return false;
285
+ const nextState = this.status !== STATUS_NONE ? this.status & STATUS_ENTER ? this._getSubstate(this.state, STATE_INITIAL) : this._getSubstate(this.state?.parent, this.state?.key) : this._newState(void 0, this.config.key, this.rootDescriptor);
286
+ if (nextState !== void 0) {
287
+ this.state = nextState;
288
+ this.status = this.status & STATUS_EXIT ? STATUS_NEXT : STATUS_FIRST;
289
+ } else {
290
+ if (this.status & STATUS_EXIT) {
291
+ this.state = this.state?.parent;
292
+ this.status = STATUS_LAST;
293
+ } else {
294
+ this.status = STATUS_LEAF;
295
+ }
296
+ if (!this.state) this.status = STATUS_FINISHED;
297
+ }
298
+ return !(this.status & STATUS_FINISHED);
299
+ }
300
+ };
301
+
302
+ // src/utils/printer.ts
303
+ var KEY_PRINTER = "printer";
304
+ function preparePrinter(process, { prefix = "", print = console.log, lineNumbers = false }) {
305
+ let lineCounter = 0;
306
+ const shift = () => {
307
+ let prefix2 = "";
308
+ for (let s = process.state?.parent; !!s; s = s.parent) {
309
+ prefix2 += " ";
310
+ }
311
+ return prefix2;
312
+ };
313
+ const getPrefix = lineNumbers ? () => `[${++lineCounter}]${shift()}` : shift;
314
+ const printer = (...args) => print(prefix, getPrefix(), ...args);
315
+ return printer;
316
+ }
317
+ function setPrinter(state, config = {}) {
318
+ const printer = preparePrinter(state.process, config);
319
+ state.setData(KEY_PRINTER, printer);
320
+ }
321
+ function setProcessPrinter(process, config = {}) {
322
+ const printer = preparePrinter(process, config);
323
+ process.setData(KEY_PRINTER, printer);
324
+ }
325
+ function getProcessPrinter(process) {
326
+ return process.getData(KEY_PRINTER) || console.log;
327
+ }
328
+ function getPrinter(state) {
329
+ return state.getData(KEY_PRINTER, true) || getProcessPrinter(state.process);
330
+ }
331
+
332
+ // src/utils/tracer.ts
333
+ function setProcessTracer(process, print) {
334
+ return process.onStateCreate((state) => {
335
+ setStateTracer(state, print);
336
+ });
337
+ }
338
+ function setStateTracer(state, print) {
339
+ state.onEnter(() => {
340
+ const printLine = print || getPrinter(state);
341
+ printLine(`<${state?.key} event="${state.process.event}">`);
342
+ });
343
+ state.onExit(async () => {
344
+ await Promise.resolve().then(async () => {
345
+ const printLine = print || getPrinter(state);
346
+ printLine(`</${state.key}> <!-- event="${state.process.event}" -->`);
347
+ });
348
+ });
349
+ }
350
+
351
+ // src/utils/process.ts
352
+ function newProcess(config, {
353
+ prefix,
354
+ print,
355
+ lineNumbers = true
356
+ }) {
357
+ let process = new FsmProcess(config);
358
+ setProcessPrinter(process, {
359
+ prefix,
360
+ print,
361
+ lineNumbers
362
+ });
363
+ setProcessTracer(process);
364
+ return process;
365
+ }
366
+
367
+ // src/utils/transitions.ts
368
+ function isStateTransitionEnabled(process, event) {
369
+ const transitions = getStateTransitions(process.state);
370
+ let active = false;
371
+ for (const [from, ev, to] of transitions) {
372
+ if (ev === event) {
373
+ active = true;
374
+ break;
375
+ }
376
+ }
377
+ return active;
378
+ }
379
+ function getStateTransitions(state) {
380
+ const result = [];
381
+ let index = {};
382
+ if (state) {
383
+ let prevStateKey = state.key;
384
+ for (let parent = state?.parent; parent; parent = parent.parent) {
385
+ if (!parent.descriptor) continue;
386
+ result.push(
387
+ ...getTransitionsFromDescriptor(parent.descriptor, prevStateKey, index)
388
+ );
389
+ prevStateKey = parent.key;
390
+ }
391
+ }
392
+ return result.reverse();
393
+ }
394
+ function getTransitionsFromDescriptor(descriptor, prevStateKey, index = {}) {
395
+ const result = [];
396
+ const prevStateKeys = [prevStateKey, "*"];
397
+ for (const prevKey of prevStateKeys) {
398
+ const targets = descriptor.transitions[prevKey];
399
+ if (targets) {
400
+ for (const [event, target] of Object.entries(targets)) {
401
+ if (index[event]) continue;
402
+ if (target) {
403
+ index[event] = true;
404
+ }
405
+ result.push([prevStateKey, event, target]);
406
+ }
407
+ }
408
+ }
409
+ return result;
410
+ }
19
411
  export {
20
412
  EVENT_ANY,
21
413
  EVENT_EMPTY,
22
414
  FsmProcess,
23
415
  FsmState,
24
416
  FsmStateDescriptor,
417
+ KEY_PRINTER,
25
418
  STATE_ANY,
26
419
  STATE_FINAL,
27
420
  STATE_INITIAL,
@@ -32,5 +425,15 @@ export {
32
425
  STATUS_LAST,
33
426
  STATUS_LEAF,
34
427
  STATUS_NEXT,
35
- STATUS_NONE
428
+ STATUS_NONE,
429
+ getPrinter,
430
+ getProcessPrinter,
431
+ getStateTransitions,
432
+ isStateTransitionEnabled,
433
+ newProcess,
434
+ preparePrinter,
435
+ setPrinter,
436
+ setProcessPrinter,
437
+ setProcessTracer,
438
+ setStateTracer
36
439
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statewalker/fsm",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "HFSM Implementation",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/statewalker/statewalker-fsm",
@@ -24,12 +24,6 @@
24
24
  "types": "./dist/index.d.ts",
25
25
  "import": "./dist/index.js",
26
26
  "default": "./dist/index.js"
27
- },
28
- "./utils": {
29
- "source": "./src/utils/index.ts",
30
- "types": "./dist/utils/index.d.ts",
31
- "import": "./dist/utils/index.js",
32
- "default": "./dist/utils/index.js"
33
27
  }
34
28
  },
35
29
  "devDependencies": {
@@ -31,17 +31,30 @@ export class FsmBaseClass {
31
31
  }
32
32
  }
33
33
 
34
+ async _runHandlerParallel(type: string, ...args: unknown[]) {
35
+ const list = this.handlers[type] || [];
36
+ await Promise.all(
37
+ list.map(async (handler) => {
38
+ try {
39
+ await handler(...args);
40
+ } catch (error) {
41
+ this._handleError(error);
42
+ }
43
+ }),
44
+ );
45
+ }
46
+
34
47
  async _runHandler(type: string, ...args: unknown[]) {
35
48
  const list = this.handlers[type] || [];
36
- const promises = list.map((handler) => handler(...args));
37
- for (const promise of promises) {
49
+ for (const handler of list) {
38
50
  try {
39
- await promise;
51
+ await handler(...args);
40
52
  } catch (error) {
41
53
  await this._handleError(error);
42
54
  }
43
55
  }
44
56
  }
57
+
45
58
  async _handleError(error: Error | unknown) {
46
59
  console.error(error);
47
60
  }
package/src/FsmProcess.ts CHANGED
@@ -38,6 +38,9 @@ export type FsmProcessDumpHandler = (
38
38
  export class FsmProcess extends FsmBaseClass {
39
39
  state?: FsmState;
40
40
  event?: string;
41
+ nextEvent?: string;
42
+ running: boolean = false;
43
+ mask: number = STATUS_LEAF;
41
44
  status: number = 0;
42
45
  config: FsmStateConfig;
43
46
  rootDescriptor: FsmStateDescriptor;
@@ -58,18 +61,34 @@ export class FsmProcess extends FsmBaseClass {
58
61
  }
59
62
  }
60
63
 
61
- async dispatch(event: string, mask: number = STATUS_LEAF) {
62
- this.event = event;
63
- while (true) {
64
- if (this.status & STATUS_EXIT) {
65
- await this.state?._runHandler("onExit", this.state);
64
+ async dispatch(event: string): Promise<boolean> {
65
+ this.nextEvent = event;
66
+ if (!this.running && !(this.status & STATUS_FINISHED)) {
67
+ this.running = true;
68
+ try {
69
+ this.event = this.nextEvent;
70
+ this.nextEvent = undefined;
71
+ while (true) {
72
+ // ---
73
+ if (this.status & STATUS_EXIT) {
74
+ await this.state?._runHandler("onExit", this.state);
75
+ }
76
+ if (!this._update()) break;
77
+ if (this.status & STATUS_ENTER) {
78
+ await this.state?._runHandler("onEnter", this.state);
79
+ }
80
+ if (this.status & this.mask) break;
81
+ // ---
82
+ }
83
+ } finally {
84
+ this.running = false;
66
85
  }
67
- if (!this._update()) return false;
68
- if (this.status & STATUS_ENTER) {
69
- await this.state?._runHandler("onEnter", this.state);
86
+ if (this.nextEvent !== undefined) {
87
+ await new Promise((r) => setImmediate(r));
88
+ return this.dispatch(this.nextEvent);
70
89
  }
71
- if (this.status & mask) return true;
72
90
  }
91
+ return !(this.status & STATUS_FINISHED);
73
92
  }
74
93
 
75
94
  async dump(...args: unknown[]): Promise<FsmProcessDump> {
@@ -138,7 +157,7 @@ export class FsmProcess extends FsmBaseClass {
138
157
  descriptor: FsmStateDescriptor | undefined,
139
158
  ) {
140
159
  const state = new FsmState(this, parent, key, descriptor);
141
- this._runHandler("onStateCreate", state);
160
+ this._runHandlerParallel("onStateCreate", state);
142
161
  return state;
143
162
  }
144
163
 
package/src/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from "./FsmProcess.ts";
2
2
  export * from "./FsmState.ts";
3
3
  export * from "./FsmStateConfig.ts";
4
4
  export * from "./FsmStateDescriptor.ts";
5
+ export * from "./utils/index.ts";
@@ -1,6 +1,4 @@
1
- export * from "./handlers.ts";
2
1
  export * from "./printer.ts";
3
2
  export * from "./process.ts";
4
3
  export * from "./tracer.ts";
5
4
  export * from "./transitions.ts";
6
- export * from "./newFsmStateHandler.ts";