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.
@@ -798,9 +798,11 @@ var WorkerClusterRuntime = class {
798
798
  this.handlers.onEvent(message.eventType, message.payload, message.sourceWorkerId, message.originTabId);
799
799
  return;
800
800
  case "REGISTRY":
801
- default:
802
801
  this.reconcile();
803
802
  return;
803
+ default:
804
+ this.handlers.onUnknownMessage?.(message);
805
+ return;
804
806
  }
805
807
  };
806
808
  /** Handle a point-to-point CONTROL message (SUBSCRIBE / UNSUBSCRIBE / PUBLISH). */
@@ -1197,6 +1199,9 @@ var DataBusTraceReporter = class {
1197
1199
  metricsIntervalMs;
1198
1200
  sink;
1199
1201
  now;
1202
+ asyncSink;
1203
+ pendingEvents = [];
1204
+ sinkFlushScheduled = false;
1200
1205
  intervalHandle = null;
1201
1206
  intervalStartedAt = 0;
1202
1207
  // A reporter may be flushed explicitly before start(), but once stop() is
@@ -1218,6 +1223,7 @@ var DataBusTraceReporter = class {
1218
1223
  this.mode = options?.mode ?? "all";
1219
1224
  this.metricsIntervalMs = normalizeInterval(options?.metricsIntervalMs);
1220
1225
  this.sink = options?.sink ?? (() => void 0);
1226
+ this.asyncSink = options?.asyncSink ?? false;
1221
1227
  this.now = now;
1222
1228
  }
1223
1229
  /** Start the periodic metrics flush interval. No-op when mode is 'events'
@@ -1344,6 +1350,22 @@ var DataBusTraceReporter = class {
1344
1350
  this.dedupSuppressed = 0;
1345
1351
  }
1346
1352
  emit(event) {
1353
+ if (this.asyncSink) {
1354
+ this.pendingEvents.push(event);
1355
+ if (!this.sinkFlushScheduled) {
1356
+ this.sinkFlushScheduled = true;
1357
+ queueMicrotask(() => {
1358
+ this.sinkFlushScheduled = false;
1359
+ const events = this.pendingEvents;
1360
+ this.pendingEvents = [];
1361
+ for (const queued of events) this.emitSync(queued);
1362
+ });
1363
+ }
1364
+ return;
1365
+ }
1366
+ this.emitSync(event);
1367
+ }
1368
+ emitSync(event) {
1347
1369
  try {
1348
1370
  this.sink(event);
1349
1371
  } catch (error) {