@rotorsoft/act 1.23.24 → 1.23.26

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/dist/index.js CHANGED
@@ -115,6 +115,27 @@ function current_version_of(deprecated_name, all_names) {
115
115
  return highest && highest.version > target.version ? highest.name : void 0;
116
116
  }
117
117
 
118
+ // src/internal/walk-streams.ts
119
+ var DEFAULT_STREAM_PAGE = 500;
120
+ async function walk_streams(store2, callback, query) {
121
+ const page_size = query?.limit ?? DEFAULT_STREAM_PAGE;
122
+ let after = query?.after;
123
+ let total = 0;
124
+ for (; ; ) {
125
+ let last;
126
+ const { count } = await store2.query_streams(
127
+ (position) => {
128
+ last = position.stream;
129
+ callback(position);
130
+ },
131
+ { ...query, after, limit: page_size }
132
+ );
133
+ total += count;
134
+ if (count < page_size) return total;
135
+ after = last;
136
+ }
137
+ }
138
+
118
139
  // src/internal/audit.ts
119
140
  var DEFAULTS = {
120
141
  idle_days: 90,
@@ -151,7 +172,7 @@ async function* audit(deps, categories, options = {}) {
151
172
  }
152
173
  }
153
174
  if (need_streams) {
154
- await deps.store().query_streams((pos) => {
175
+ await walk_streams(deps.store(), (pos) => {
155
176
  for (const p of passes) p.on_stream?.(pos);
156
177
  });
157
178
  }
@@ -2495,6 +2516,20 @@ var EMPTY_DRAIN = {
2495
2516
  acked: [],
2496
2517
  blocked: []
2497
2518
  };
2519
+ var contain = (logger, sink, fn) => {
2520
+ try {
2521
+ fn();
2522
+ } catch (error) {
2523
+ logger.error(error, `${sink} listener threw`);
2524
+ }
2525
+ };
2526
+ var contain_async = async (logger, sink, fn) => {
2527
+ try {
2528
+ await fn();
2529
+ } catch (error) {
2530
+ logger.error(error, `${sink} listener threw`);
2531
+ }
2532
+ };
2498
2533
  var DrainController = class {
2499
2534
  _armed = false;
2500
2535
  _locked = false;
@@ -2620,9 +2655,20 @@ var DrainController = class {
2620
2655
  if (next !== void 0) this._defer.set(h.lease.stream, next);
2621
2656
  }
2622
2657
  if (this._defer.size > 0) this._defer.schedule();
2623
- if (acked.length) this._deps.on_acked(acked);
2624
- if (blocked.length) this._deps.on_blocked(blocked);
2625
- if (closeable.length) await this._deps.on_close(closeable);
2658
+ if (acked.length)
2659
+ contain(this._deps.logger, "acked", () => this._deps.on_acked(acked));
2660
+ if (blocked.length)
2661
+ contain(
2662
+ this._deps.logger,
2663
+ "blocked",
2664
+ () => this._deps.on_blocked(blocked)
2665
+ );
2666
+ if (closeable.length)
2667
+ await contain_async(
2668
+ this._deps.logger,
2669
+ "close",
2670
+ () => this._deps.on_close(closeable)
2671
+ );
2626
2672
  const has_errors = handled.some(({ error }) => error);
2627
2673
  if (!acked.length && !blocked.length && !has_errors) this._armed = false;
2628
2674
  return { fetched, leased, acked, blocked };
@@ -3318,7 +3364,7 @@ var Act = class {
3318
3364
  */
3319
3365
  async _seed_persisted_defers() {
3320
3366
  const now = Date.now();
3321
- await store().query_streams((pos) => {
3367
+ await walk_streams(store(), (pos) => {
3322
3368
  if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
3323
3369
  const controller = this._drain_controllers.get(pos.lane ?? "default");
3324
3370
  controller?.seed_defer(pos.stream, pos.deferred_at);