@rotorsoft/act 1.33.13 → 1.33.14

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
@@ -1259,11 +1259,8 @@ var CorrelateCycle = class {
1259
1259
  await this._init();
1260
1260
  const epoch = this._epoch;
1261
1261
  const idle = () => ({
1262
- subscribed: 0,
1263
- last_id: this._checkpoint,
1264
- read: false,
1265
- marked: 0,
1266
- scanned: false
1262
+ kind: "idle",
1263
+ last_id: this._checkpoint
1267
1264
  });
1268
1265
  if (this._raised === this._lowered) return idle();
1269
1266
  const raised = this._raised;
@@ -1389,11 +1386,11 @@ var CorrelateCycle = class {
1389
1386
  lane
1390
1387
  });
1391
1388
  }
1392
- return { subscribed, last_id, read, marked, scanned: true };
1389
+ return { kind: "scanned", last_id, subscribed, marked, read };
1393
1390
  }
1394
1391
  this._checkpoint = last_id;
1395
1392
  if (!stopped && found !== query.limit) this._lowered = raised;
1396
- return { subscribed: 0, last_id, read, marked: 0, scanned: true };
1393
+ return { kind: "scanned", last_id, subscribed: 0, marked: 0, read };
1397
1394
  }
1398
1395
  /**
1399
1396
  * Read the row of each target this scan had no record of (new or evicted),
@@ -2868,11 +2865,12 @@ var SettleLoop = class {
2868
2865
  this._inflight = (async () => {
2869
2866
  const passes = [];
2870
2867
  for (let i = 0; i < maxPasses && !this._stopped; i++) {
2871
- const { subscribed, read, scanned } = await this._deps.correlate(correlate_query);
2868
+ const pass = await this._deps.correlate(correlate_query);
2869
+ const scanned = pass.kind === "scanned";
2872
2870
  if (scanned) this._deps.breaker.passed();
2873
2871
  const drain = await this._deps.drain(drain_options);
2874
2872
  passes.push(drain);
2875
- const made_progress = subscribed > 0 || drain.leased.length > 0 || read;
2873
+ const made_progress = drain.leased.length > 0 || scanned && (pass.subscribed > 0 || pass.read);
2876
2874
  if (!made_progress) break;
2877
2875
  }
2878
2876
  if (passes.length) this._deps.on_settled(merge_drains(passes));
@@ -3180,7 +3178,7 @@ var Act = class {
3180
3178
  _build_settle(options) {
3181
3179
  return new SettleLoop(
3182
3180
  {
3183
- correlate: (q) => this._correlate_scanned(
3181
+ correlate: (q) => this._correlate_pass(
3184
3182
  { ...q, limit: q.limit ?? this._poll_limit ?? 100 },
3185
3183
  true
3186
3184
  ),
@@ -3243,15 +3241,16 @@ var Act = class {
3243
3241
  if (running.length === 0 && !settling) return;
3244
3242
  const grace = grace_ms ?? this._derive_grace_ms(running, !!settling);
3245
3243
  if (grace <= 0) return;
3246
- const inflight = running.map((c) => c.inflight);
3247
- if (settling) inflight.push(settling);
3248
3244
  let timer;
3249
3245
  const budget = new Promise((resolve) => {
3250
3246
  timer = setTimeout(resolve, grace);
3251
3247
  timer.unref();
3252
3248
  });
3253
3249
  try {
3254
- await Promise.race([Promise.all(inflight), budget]);
3250
+ await Promise.race([
3251
+ Promise.all([...running.map((c) => c.inflight), settling]),
3252
+ budget
3253
+ ]);
3255
3254
  } finally {
3256
3255
  clearTimeout(timer);
3257
3256
  }
@@ -3542,17 +3541,20 @@ var Act = class {
3542
3541
  * @see {@link start_correlations} for automatic periodic correlation
3543
3542
  */
3544
3543
  async correlate(query = { after: -1, limit: 10 }) {
3545
- const { subscribed, last_id } = await this._correlate_scanned(query);
3546
- return { subscribed, last_id };
3544
+ const pass = await this._correlate_pass(query);
3545
+ return {
3546
+ subscribed: pass.kind === "scanned" ? pass.subscribed : 0,
3547
+ last_id: pass.last_id
3548
+ };
3547
3549
  }
3548
- /** `correlate` plus `scanned`, which settle needs for the breaker. */
3549
- async _correlate_scanned(query, lease = false) {
3550
- if (!this._drain)
3551
- return { subscribed: 0, last_id: -1, read: false, scanned: false };
3550
+ /** One correlate pass; arms every lane when it found work. */
3551
+ async _correlate_pass(query, lease = false) {
3552
+ if (!this._drain) return { kind: "idle", last_id: -1 };
3552
3553
  return this._scoped(async () => {
3553
- const { subscribed, last_id, read, marked, scanned } = await this._correlate.correlate(query, lease);
3554
- if (subscribed > 0 || marked > 0) this._arm_all();
3555
- return { subscribed, last_id, read, scanned };
3554
+ const pass = await this._correlate.correlate(query, lease);
3555
+ if (pass.kind === "scanned" && (pass.subscribed > 0 || pass.marked > 0))
3556
+ this._arm_all();
3557
+ return pass;
3556
3558
  });
3557
3559
  }
3558
3560
  /**