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.
@@ -1199,6 +1199,9 @@ var DataBusTraceReporter = class {
1199
1199
  metricsIntervalMs;
1200
1200
  sink;
1201
1201
  now;
1202
+ asyncSink;
1203
+ pendingEvents = [];
1204
+ sinkFlushScheduled = false;
1202
1205
  intervalHandle = null;
1203
1206
  intervalStartedAt = 0;
1204
1207
  // A reporter may be flushed explicitly before start(), but once stop() is
@@ -1220,6 +1223,7 @@ var DataBusTraceReporter = class {
1220
1223
  this.mode = options?.mode ?? "all";
1221
1224
  this.metricsIntervalMs = normalizeInterval(options?.metricsIntervalMs);
1222
1225
  this.sink = options?.sink ?? (() => void 0);
1226
+ this.asyncSink = options?.asyncSink ?? false;
1223
1227
  this.now = now;
1224
1228
  }
1225
1229
  /** Start the periodic metrics flush interval. No-op when mode is 'events'
@@ -1346,6 +1350,22 @@ var DataBusTraceReporter = class {
1346
1350
  this.dedupSuppressed = 0;
1347
1351
  }
1348
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) {
1349
1369
  try {
1350
1370
  this.sink(event);
1351
1371
  } catch (error) {