cross-tab-worker-databus 0.20.62 → 0.20.64

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.
@@ -773,9 +773,11 @@ var WorkerClusterRuntime = class {
773
773
  this.handlers.onEvent(message.eventType, message.payload, message.sourceWorkerId, message.originTabId);
774
774
  return;
775
775
  case "REGISTRY":
776
- default:
777
776
  this.reconcile();
778
777
  return;
778
+ default:
779
+ this.handlers.onUnknownMessage?.(message);
780
+ return;
779
781
  }
780
782
  };
781
783
  /** Handle a point-to-point CONTROL message (SUBSCRIBE / UNSUBSCRIBE / PUBLISH). */
@@ -1172,6 +1174,9 @@ var DataBusTraceReporter = class {
1172
1174
  metricsIntervalMs;
1173
1175
  sink;
1174
1176
  now;
1177
+ asyncSink;
1178
+ pendingEvents = [];
1179
+ sinkFlushScheduled = false;
1175
1180
  intervalHandle = null;
1176
1181
  intervalStartedAt = 0;
1177
1182
  // A reporter may be flushed explicitly before start(), but once stop() is
@@ -1193,6 +1198,7 @@ var DataBusTraceReporter = class {
1193
1198
  this.mode = options?.mode ?? "all";
1194
1199
  this.metricsIntervalMs = normalizeInterval(options?.metricsIntervalMs);
1195
1200
  this.sink = options?.sink ?? (() => void 0);
1201
+ this.asyncSink = options?.asyncSink ?? false;
1196
1202
  this.now = now;
1197
1203
  }
1198
1204
  /** Start the periodic metrics flush interval. No-op when mode is 'events'
@@ -1319,6 +1325,22 @@ var DataBusTraceReporter = class {
1319
1325
  this.dedupSuppressed = 0;
1320
1326
  }
1321
1327
  emit(event) {
1328
+ if (this.asyncSink) {
1329
+ this.pendingEvents.push(event);
1330
+ if (!this.sinkFlushScheduled) {
1331
+ this.sinkFlushScheduled = true;
1332
+ queueMicrotask(() => {
1333
+ this.sinkFlushScheduled = false;
1334
+ const events = this.pendingEvents;
1335
+ this.pendingEvents = [];
1336
+ for (const queued of events) this.emitSync(queued);
1337
+ });
1338
+ }
1339
+ return;
1340
+ }
1341
+ this.emitSync(event);
1342
+ }
1343
+ emitSync(event) {
1322
1344
  try {
1323
1345
  this.sink(event);
1324
1346
  } catch (error) {