cross-tab-worker-databus 0.20.94 → 0.20.95

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.
@@ -542,11 +542,11 @@ var BatchingStorageWriter = class {
542
542
  if (typeof queueMicrotask === "function") queueMicrotask(flush);
543
543
  else setTimeout(flush, 0);
544
544
  }
545
- // Schedule a single retry timer. The guard ensures only one retry is in
546
- // flight at a time; subsequent scheduleRetry calls during the wait are
547
- // no-ops because the first retry will re-flush all pending keys together.
545
+ // Arm the single backoff timer for the pass that just failed. Exactly one
546
+ // retry can be in flight because flush() the only caller — cancels any
547
+ // armed retry on entry and stops at the first failing key, so this always
548
+ // runs with `retryHandle` cleared.
548
549
  scheduleRetry() {
549
- if (this.retryHandle !== null) return;
550
550
  this.retryHandle = setTimeout(() => {
551
551
  this.retryHandle = null;
552
552
  this.flush();
@@ -747,9 +747,8 @@ var WorkerClusterRuntime = class {
747
747
  touchRouteOwnerCache(topicKey, value) {
748
748
  if (this.routeOwnerCache.has(topicKey)) this.routeOwnerCache.delete(topicKey);
749
749
  this.routeOwnerCache.set(topicKey, value);
750
- while (this.routeOwnerCache.size > this.routeOwnerCacheMax) {
751
- const oldest = this.routeOwnerCache.keys().next().value;
752
- if (oldest === void 0) break;
750
+ for (const oldest of this.routeOwnerCache.keys()) {
751
+ if (this.routeOwnerCache.size <= this.routeOwnerCacheMax) break;
753
752
  this.routeOwnerCache.delete(oldest);
754
753
  }
755
754
  }
@@ -2407,9 +2406,8 @@ var DedupManager = class {
2407
2406
  this.accepted += 1;
2408
2407
  this.windowAccepted += 1;
2409
2408
  this.trace.recordDedupAccepted();
2410
- while (this.seenMessageIds.size > this.maxEntries) {
2411
- const oldest = this.seenMessageIds.keys().next().value;
2412
- if (oldest === void 0) break;
2409
+ for (const oldest of this.seenMessageIds.keys()) {
2410
+ if (this.seenMessageIds.size <= this.maxEntries) break;
2413
2411
  this.seenMessageIds.delete(oldest);
2414
2412
  }
2415
2413
  return false;
@@ -2470,7 +2468,7 @@ var DedupManager = class {
2470
2468
  };
2471
2469
 
2472
2470
  // src/core/version.ts
2473
- var SDK_VERSION = true ? "0.20.94" : "";
2471
+ var SDK_VERSION = true ? "0.20.95" : "";
2474
2472
 
2475
2473
  // src/core/data-bus.ts
2476
2474
  var DEFAULT_REPLAY_MAX_PER_TOPIC = 100;
@@ -3926,12 +3924,13 @@ var CentrifugeWorkerTransport = class {
3926
3924
  heartbeatHandle = null;
3927
3925
  localSession = null;
3928
3926
  handlers = null;
3929
- // Monotonically increasing counter, bumped each time a backend is created.
3930
- // Used to ignore late error events from a superseded Worker.
3927
+ // Monotonically increasing counter, bumped each time a backend is created or
3928
+ // the transport stops. Only the asynchronous credential bridge compares it:
3929
+ // a provider may settle after the Worker it was answering is gone. Worker
3930
+ // error events need no such check — stop() and onWorkerFailed() remove those
3931
+ // listeners before the generation moves on, so a superseded backend can no
3932
+ // longer reach this object at all.
3931
3933
  generation = 0;
3932
- // Generation captured when the current backend was created. Error handlers
3933
- // only act when the backend that registered them is still current.
3934
- backendGeneration = 0;
3935
3934
  get diagnosticsBackend() {
3936
3935
  return this.backend ?? "uninitialized";
3937
3936
  }
@@ -4024,7 +4023,7 @@ var CentrifugeWorkerTransport = class {
4024
4023
  }
4025
4024
  /** Create and initialise a dedicated Worker, then send the INIT message. */
4026
4025
  startDedicatedWorker(input) {
4027
- this.backendGeneration = ++this.generation;
4026
+ this.generation += 1;
4028
4027
  const worker = (this.workerFactory ?? createDefaultWorker)();
4029
4028
  this.worker = worker;
4030
4029
  worker.addEventListener("message", this.handleMessage);
@@ -4033,7 +4032,7 @@ var CentrifugeWorkerTransport = class {
4033
4032
  }
4034
4033
  /** Create and initialise a SharedWorker, open the MessagePort, and send the INIT message. */
4035
4034
  startSharedWorker(input) {
4036
- this.backendGeneration = ++this.generation;
4035
+ this.generation += 1;
4037
4036
  const shared = (this.sharedWorkerFactory ?? createDefaultSharedWorker)();
4038
4037
  this.sharedWorker = shared;
4039
4038
  const port = shared.port;
@@ -4103,9 +4102,10 @@ var CentrifugeWorkerTransport = class {
4103
4102
  }
4104
4103
  /** Handle a Worker-level failure (crash, message decode error). Discards the
4105
4104
  * dead backend so a later start()/reopen can rebuild from scratch, and
4106
- * signals an error status so the DataBus can trigger recovery.
4107
- * Only invoked when the generation guard confirms the failing backend is
4108
- * still current late errors from a superseded Worker are silently dropped. */
4105
+ * signals an error status so the DataBus can trigger recovery. A superseded
4106
+ * backend cannot reach this: its listeners are removed before the transport
4107
+ * moves on, which is what keeps late Worker errors from tearing down a fresh
4108
+ * session (pinned by 'ignores error events from a superseded worker'). */
4109
4109
  onWorkerFailed(message) {
4110
4110
  this.worker?.removeEventListener("message", this.handleMessage);
4111
4111
  this.worker?.removeEventListener("error", this.handleWorkerError);
@@ -4136,15 +4136,12 @@ var CentrifugeWorkerTransport = class {
4136
4136
  this.heartbeatHandle = null;
4137
4137
  }
4138
4138
  handleWorkerError = () => {
4139
- if (this.generation !== this.backendGeneration) return;
4140
4139
  this.onWorkerFailed("Centrifuge worker failed.");
4141
4140
  };
4142
4141
  handlePortError = () => {
4143
- if (this.generation !== this.backendGeneration) return;
4144
4142
  this.onWorkerFailed("Centrifuge shared worker message decoding failed.");
4145
4143
  };
4146
4144
  handleSharedWorkerError = () => {
4147
- if (this.generation !== this.backendGeneration) return;
4148
4145
  this.onWorkerFailed("Centrifuge shared worker failed.");
4149
4146
  };
4150
4147
  /** Clear the Worker/port/backend references after a failure or stop. */