@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 CHANGED
@@ -608,13 +608,19 @@ var Queue = class {
608
608
  front = [];
609
609
  back = [];
610
610
  backHead = 0;
611
+ fifo;
612
+ constructor(fifo) {
613
+ this.fifo = fifo;
614
+ }
611
615
  len() {
612
- return this.front.length + (this.back.length - this.backHead);
616
+ return this.front.length + (this.fifo ? this.fifo.len() : this.back.length - this.backHead);
613
617
  }
614
618
  pop() {
615
619
  var event2;
616
620
  if (this.front.length > 0) {
617
621
  event2 = this.front.pop();
622
+ } else if (this.fifo) {
623
+ event2 = this.fifo.pop();
618
624
  } else if (this.backHead < this.back.length) {
619
625
  event2 = this.back[this.backHead];
620
626
  this.back[this.backHead] = void 0;
@@ -626,14 +632,13 @@ var Queue = class {
626
632
  }
627
633
  return event2;
628
634
  }
629
- push(...events) {
630
- for (var i = 0; i < events.length; i++) {
631
- var event2 = events[i];
632
- if (isKind(event2.kind, kinds.CompletionEvent)) {
633
- this.front.push(event2);
634
- } else {
635
- this.back.push(event2);
636
- }
635
+ push(event2) {
636
+ if (isKind(event2.kind, kinds.CompletionEvent)) {
637
+ this.front.push(event2);
638
+ } else if (this.fifo) {
639
+ this.fifo.push(event2);
640
+ } else {
641
+ this.back.push(event2);
637
642
  }
638
643
  }
639
644
  };
@@ -812,7 +817,7 @@ var HSM = class _HSM {
812
817
  this.ctx = ctxOrInstance;
813
818
  this.model = maybeModelOrConfig;
814
819
  this.currentState = this.model;
815
- this.queue = new Queue();
820
+ this.queue = new Queue(maybeConfig?.queue);
816
821
  this.active = {};
817
822
  this.processing = false;
818
823
  this.id = id2;