cross-tab-worker-databus 0.21.23 → 0.21.25

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.
@@ -837,7 +837,7 @@ var WorkerClusterRuntime = class {
837
837
  */
838
838
  stop() {
839
839
  this.lifecycleGeneration += 1;
840
- if (!this.started && !this.suspended) return;
840
+ if (!this.started && !this.suspended && !this.lifecycleListening) return;
841
841
  this.pause();
842
842
  this.flushStorage();
843
843
  this.removeLifecycleListeners();
@@ -865,6 +865,12 @@ var WorkerClusterRuntime = class {
865
865
  this.channel = null;
866
866
  }
867
867
  if (!this.channel) this.storage = null;
868
+ if (!this.started) {
869
+ const channel = this.channel;
870
+ this.channel = null;
871
+ channel?.close();
872
+ return;
873
+ }
868
874
  this.channel?.addEventListener("message", this.handleMessage);
869
875
  const now = this.environment.now();
870
876
  this.currentRecord = {
@@ -880,6 +886,7 @@ var WorkerClusterRuntime = class {
880
886
  if (!this.storage) this.sendControl(this.workerId, CONTROL_ACTION.SUBSCRIBE, topic, topicKey);
881
887
  else this.writeSubscriber(topicKey);
882
888
  }
889
+ if (!this.started) return;
883
890
  this.reconcile();
884
891
  this.heartbeatHandle = this.environment.setInterval(() => {
885
892
  this.writeRecord(false);
@@ -2579,7 +2586,7 @@ var SDK_VERSION = (
2579
2586
  // declaration's type is `string | undefined` and the export's is `string`
2580
2587
  // (dropping the conditional is TS2322, measured). Recorded here so the leg reads
2581
2588
  // as a shape the harness cannot reach rather than as a case nobody exercised.
2582
- true ? "0.21.23" : ""
2589
+ true ? "0.21.25" : ""
2583
2590
  );
2584
2591
 
2585
2592
  // src/core/data-bus.ts
@@ -3393,15 +3400,21 @@ var CrossTabDataBus = class {
3393
3400
  }
3394
3401
  /** Deliver a message to every local handler registered for its topic,
3395
3402
  * plus every handler registered with a wildcard subscription that matches
3396
- * (e.g. a handler subscribed to "chat.*" receives "chat.room.1"). */
3403
+ * (e.g. a handler subscribed to "chat.*" receives "chat.room.1"). Both sets are
3404
+ * collected before the first handler runs, so a publication is delivered to the
3405
+ * subscribers that existed when its delivery began — see the note in the body. */
3397
3406
  dispatch(message) {
3398
3407
  this.trace.recordDispatched(message.topic);
3399
- this.invokeHandlers(this.topicHandlers.get(message.topic) ?? [], (handler) => handler(message));
3408
+ const exactHandlers = this.topicHandlers.get(message.topic);
3409
+ const delivered = exactHandlers ? Array.from(exactHandlers) : [];
3410
+ const wildcards = [];
3400
3411
  for (const [pattern, handlers] of this.topicHandlers) {
3401
3412
  if (pattern !== message.topic && topicMatchesPattern(pattern, message.topic)) {
3402
- this.invokeHandlers(handlers, (handler) => handler(message));
3413
+ for (const handler of handlers) wildcards.push(handler);
3403
3414
  }
3404
3415
  }
3416
+ this.invokeHandlers(delivered, (handler) => handler(message));
3417
+ this.invokeHandlers(wildcards, (handler) => handler(message));
3405
3418
  this.replayManager.record(message);
3406
3419
  }
3407
3420
  /**