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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.20.64] - 2026-09-05
4
+
5
+ ### Added
6
+ - Added opt-in `asyncSink` trace mode, batching sink delivery onto a microtask while preserving event order and sink error isolation.
7
+ - Added regression coverage for asynchronous trace batching (339 unit tests).
8
+
3
9
  ## [0.20.63] - 2026-09-05
4
10
 
5
11
  ### Added
@@ -2,7 +2,7 @@ import {
2
2
  CrossTabDataBus,
3
3
  parseDataBusPublication,
4
4
  selectWorkerBackend
5
- } from "./chunk-ZHCGYGL3.js";
5
+ } from "./chunk-5CP7GNU6.js";
6
6
 
7
7
  // src/centrifuge-session.ts
8
8
  import { Centrifuge } from "centrifuge";
@@ -1158,6 +1158,9 @@ var DataBusTraceReporter = class {
1158
1158
  metricsIntervalMs;
1159
1159
  sink;
1160
1160
  now;
1161
+ asyncSink;
1162
+ pendingEvents = [];
1163
+ sinkFlushScheduled = false;
1161
1164
  intervalHandle = null;
1162
1165
  intervalStartedAt = 0;
1163
1166
  // A reporter may be flushed explicitly before start(), but once stop() is
@@ -1179,6 +1182,7 @@ var DataBusTraceReporter = class {
1179
1182
  this.mode = options?.mode ?? "all";
1180
1183
  this.metricsIntervalMs = normalizeInterval(options?.metricsIntervalMs);
1181
1184
  this.sink = options?.sink ?? (() => void 0);
1185
+ this.asyncSink = options?.asyncSink ?? false;
1182
1186
  this.now = now;
1183
1187
  }
1184
1188
  /** Start the periodic metrics flush interval. No-op when mode is 'events'
@@ -1305,6 +1309,22 @@ var DataBusTraceReporter = class {
1305
1309
  this.dedupSuppressed = 0;
1306
1310
  }
1307
1311
  emit(event) {
1312
+ if (this.asyncSink) {
1313
+ this.pendingEvents.push(event);
1314
+ if (!this.sinkFlushScheduled) {
1315
+ this.sinkFlushScheduled = true;
1316
+ queueMicrotask(() => {
1317
+ this.sinkFlushScheduled = false;
1318
+ const events = this.pendingEvents;
1319
+ this.pendingEvents = [];
1320
+ for (const queued of events) this.emitSync(queued);
1321
+ });
1322
+ }
1323
+ return;
1324
+ }
1325
+ this.emitSync(event);
1326
+ }
1327
+ emitSync(event) {
1308
1328
  try {
1309
1329
  this.sink(event);
1310
1330
  } catch (error) {
@@ -2309,4 +2329,4 @@ export {
2309
2329
  parseDataBusPublication,
2310
2330
  selectWorkerBackend
2311
2331
  };
2312
- //# sourceMappingURL=chunk-ZHCGYGL3.js.map
2332
+ //# sourceMappingURL=chunk-5CP7GNU6.js.map