@stateforward/hsm.ts 0.1.0 → 0.1.2
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.cjs +15 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +15 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -81,12 +81,18 @@ type Config = {
|
|
|
81
81
|
clearTimeout?: CancelFunction;
|
|
82
82
|
now?: () => number;
|
|
83
83
|
};
|
|
84
|
+
queue?: QueueShape;
|
|
84
85
|
};
|
|
85
86
|
type ClockConfig = {
|
|
86
87
|
setTimeout: TimerFunction;
|
|
87
88
|
clearTimeout: CancelFunction;
|
|
88
89
|
now: () => number;
|
|
89
90
|
};
|
|
91
|
+
type QueueShape = {
|
|
92
|
+
push: (event: EventRecord) => void;
|
|
93
|
+
pop: () => EventRecord | undefined;
|
|
94
|
+
len: () => number;
|
|
95
|
+
};
|
|
90
96
|
type StripLeadingSlash<S extends string> = S extends `/${infer Rest}` ? Rest : S;
|
|
91
97
|
type StripTrailingSlash<S extends string> = S extends `${infer Rest}/` ? Rest : S;
|
|
92
98
|
type PathParts<S extends string> = S extends '' ? [] : S extends `${infer Head}/${infer Tail}` ? [Head, ...PathParts<Tail>] : [S];
|
|
@@ -767,9 +773,11 @@ declare class Queue {
|
|
|
767
773
|
front: EventRecord[];
|
|
768
774
|
back: Array<EventRecord | undefined>;
|
|
769
775
|
backHead: number;
|
|
776
|
+
private fifo?;
|
|
777
|
+
constructor(fifo?: QueueShape);
|
|
770
778
|
len(): number;
|
|
771
779
|
pop(): EventRecord | undefined;
|
|
772
|
-
push(
|
|
780
|
+
push(event: EventRecord): void;
|
|
773
781
|
}
|
|
774
782
|
type InstanceConstructor = {
|
|
775
783
|
new (): Instance;
|
package/dist/index.d.ts
CHANGED
|
@@ -81,12 +81,18 @@ type Config = {
|
|
|
81
81
|
clearTimeout?: CancelFunction;
|
|
82
82
|
now?: () => number;
|
|
83
83
|
};
|
|
84
|
+
queue?: QueueShape;
|
|
84
85
|
};
|
|
85
86
|
type ClockConfig = {
|
|
86
87
|
setTimeout: TimerFunction;
|
|
87
88
|
clearTimeout: CancelFunction;
|
|
88
89
|
now: () => number;
|
|
89
90
|
};
|
|
91
|
+
type QueueShape = {
|
|
92
|
+
push: (event: EventRecord) => void;
|
|
93
|
+
pop: () => EventRecord | undefined;
|
|
94
|
+
len: () => number;
|
|
95
|
+
};
|
|
90
96
|
type StripLeadingSlash<S extends string> = S extends `/${infer Rest}` ? Rest : S;
|
|
91
97
|
type StripTrailingSlash<S extends string> = S extends `${infer Rest}/` ? Rest : S;
|
|
92
98
|
type PathParts<S extends string> = S extends '' ? [] : S extends `${infer Head}/${infer Tail}` ? [Head, ...PathParts<Tail>] : [S];
|
|
@@ -767,9 +773,11 @@ declare class Queue {
|
|
|
767
773
|
front: EventRecord[];
|
|
768
774
|
back: Array<EventRecord | undefined>;
|
|
769
775
|
backHead: number;
|
|
776
|
+
private fifo?;
|
|
777
|
+
constructor(fifo?: QueueShape);
|
|
770
778
|
len(): number;
|
|
771
779
|
pop(): EventRecord | undefined;
|
|
772
|
-
push(
|
|
780
|
+
push(event: EventRecord): void;
|
|
773
781
|
}
|
|
774
782
|
type InstanceConstructor = {
|
|
775
783
|
new (): Instance;
|
package/dist/index.js
CHANGED
|
@@ -344,13 +344,19 @@ var Queue = class {
|
|
|
344
344
|
front = [];
|
|
345
345
|
back = [];
|
|
346
346
|
backHead = 0;
|
|
347
|
+
fifo;
|
|
348
|
+
constructor(fifo) {
|
|
349
|
+
this.fifo = fifo;
|
|
350
|
+
}
|
|
347
351
|
len() {
|
|
348
|
-
return this.front.length + (this.back.length - this.backHead);
|
|
352
|
+
return this.front.length + (this.fifo ? this.fifo.len() : this.back.length - this.backHead);
|
|
349
353
|
}
|
|
350
354
|
pop() {
|
|
351
355
|
var event2;
|
|
352
356
|
if (this.front.length > 0) {
|
|
353
357
|
event2 = this.front.pop();
|
|
358
|
+
} else if (this.fifo) {
|
|
359
|
+
event2 = this.fifo.pop();
|
|
354
360
|
} else if (this.backHead < this.back.length) {
|
|
355
361
|
event2 = this.back[this.backHead];
|
|
356
362
|
this.back[this.backHead] = void 0;
|
|
@@ -362,14 +368,13 @@ var Queue = class {
|
|
|
362
368
|
}
|
|
363
369
|
return event2;
|
|
364
370
|
}
|
|
365
|
-
push(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
371
|
+
push(event2) {
|
|
372
|
+
if (isKind(event2.kind, kinds.CompletionEvent)) {
|
|
373
|
+
this.front.push(event2);
|
|
374
|
+
} else if (this.fifo) {
|
|
375
|
+
this.fifo.push(event2);
|
|
376
|
+
} else {
|
|
377
|
+
this.back.push(event2);
|
|
373
378
|
}
|
|
374
379
|
}
|
|
375
380
|
};
|
|
@@ -548,7 +553,7 @@ var HSM = class _HSM {
|
|
|
548
553
|
this.ctx = ctxOrInstance;
|
|
549
554
|
this.model = maybeModelOrConfig;
|
|
550
555
|
this.currentState = this.model;
|
|
551
|
-
this.queue = new Queue();
|
|
556
|
+
this.queue = new Queue(maybeConfig?.queue);
|
|
552
557
|
this.active = {};
|
|
553
558
|
this.processing = false;
|
|
554
559
|
this.id = id2;
|