cross-tab-worker-databus 0.20.63 → 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.
@@ -1174,6 +1174,9 @@ var DataBusTraceReporter = class {
1174
1174
  metricsIntervalMs;
1175
1175
  sink;
1176
1176
  now;
1177
+ asyncSink;
1178
+ pendingEvents = [];
1179
+ sinkFlushScheduled = false;
1177
1180
  intervalHandle = null;
1178
1181
  intervalStartedAt = 0;
1179
1182
  // A reporter may be flushed explicitly before start(), but once stop() is
@@ -1195,6 +1198,7 @@ var DataBusTraceReporter = class {
1195
1198
  this.mode = options?.mode ?? "all";
1196
1199
  this.metricsIntervalMs = normalizeInterval(options?.metricsIntervalMs);
1197
1200
  this.sink = options?.sink ?? (() => void 0);
1201
+ this.asyncSink = options?.asyncSink ?? false;
1198
1202
  this.now = now;
1199
1203
  }
1200
1204
  /** Start the periodic metrics flush interval. No-op when mode is 'events'
@@ -1321,6 +1325,22 @@ var DataBusTraceReporter = class {
1321
1325
  this.dedupSuppressed = 0;
1322
1326
  }
1323
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) {
1324
1344
  try {
1325
1345
  this.sink(event);
1326
1346
  } catch (error) {