@rotorsoft/act 1.23.23 → 1.23.25

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.cjs CHANGED
@@ -248,27 +248,6 @@ var LruMap = class {
248
248
  return this._entries.size;
249
249
  }
250
250
  };
251
- var LruSet = class {
252
- _map;
253
- constructor(maxSize) {
254
- this._map = new LruMap(maxSize);
255
- }
256
- has(value) {
257
- return this._map.has(value);
258
- }
259
- add(value) {
260
- this._map.set(value, true);
261
- }
262
- delete(value) {
263
- return this._map.delete(value);
264
- }
265
- clear() {
266
- this._map.clear();
267
- }
268
- get size() {
269
- return this._map.size;
270
- }
271
- };
272
251
 
273
252
  // src/adapters/in-memory-cache.ts
274
253
  var InMemoryCache = class {
@@ -3055,6 +3034,11 @@ var CorrelateCycle = class {
3055
3034
  _checkpoint = -1;
3056
3035
  _initialized = false;
3057
3036
  _timer = void 0;
3037
+ // target → the priority it was last subscribed at. A dynamic target is
3038
+ // re-subscribed (so the store's `GREATEST` upsert runs) only when a later
3039
+ // scan resolves a *higher* priority for it — the runtime `max()` invariant
3040
+ // (#1363). Static targets are recorded at +Infinity so a dynamic resolution
3041
+ // never re-opens them (their priority is owned by the build-time subscribe).
3058
3042
  _subscribed;
3059
3043
  _registry;
3060
3044
  _static_targets;
@@ -3096,7 +3080,7 @@ var CorrelateCycle = class {
3096
3080
  on_init_async,
3097
3081
  cold_start_back_scan = DEFAULT_COLD_START_BACK_SCAN
3098
3082
  }) {
3099
- this._subscribed = new LruSet(max_subscribed_streams);
3083
+ this._subscribed = new LruMap(max_subscribed_streams);
3100
3084
  this._registry = registry;
3101
3085
  this._static_targets = static_targets;
3102
3086
  this._has_dynamic_resolvers = has_dynamic_resolvers;
@@ -3136,7 +3120,7 @@ var CorrelateCycle = class {
3136
3120
  this._checkpoint = this._has_dynamic_resolvers ? Math.max(-1, watermark - this._cold_start_back_scan) : watermark;
3137
3121
  this._on_init?.();
3138
3122
  for (const { stream } of this._static_targets) {
3139
- this._subscribed.add(stream);
3123
+ this._subscribed.set(stream, Number.POSITIVE_INFINITY);
3140
3124
  }
3141
3125
  await this._on_init_async?.();
3142
3126
  }
@@ -3160,7 +3144,7 @@ var CorrelateCycle = class {
3160
3144
  for (const reaction of register.reactions.values()) {
3161
3145
  if (typeof reaction.resolver !== "function") continue;
3162
3146
  const resolved = reaction.resolver(event);
3163
- if (resolved && !this._subscribed.has(resolved.target)) {
3147
+ if (resolved && (resolved.priority ?? 0) > (this._subscribed.get(resolved.target) ?? Number.NEGATIVE_INFINITY)) {
3164
3148
  const incoming_priority = resolved.priority ?? 0;
3165
3149
  const entry = correlated.get(resolved.target) || {
3166
3150
  source: resolved.source,
@@ -3196,8 +3180,8 @@ var CorrelateCycle = class {
3196
3180
  const { subscribed } = await this._cd.subscribe(streams);
3197
3181
  this._checkpoint = last_id;
3198
3182
  if (subscribed) {
3199
- for (const { stream } of streams) {
3200
- this._subscribed.add(stream);
3183
+ for (const { stream, priority } of streams) {
3184
+ this._subscribed.set(stream, priority);
3201
3185
  }
3202
3186
  }
3203
3187
  return { subscribed, last_id };
@@ -4033,6 +4017,20 @@ var EMPTY_DRAIN = {
4033
4017
  acked: [],
4034
4018
  blocked: []
4035
4019
  };
4020
+ var contain = (logger, sink, fn) => {
4021
+ try {
4022
+ fn();
4023
+ } catch (error) {
4024
+ logger.error(error, `${sink} listener threw`);
4025
+ }
4026
+ };
4027
+ var contain_async = async (logger, sink, fn) => {
4028
+ try {
4029
+ await fn();
4030
+ } catch (error) {
4031
+ logger.error(error, `${sink} listener threw`);
4032
+ }
4033
+ };
4036
4034
  var DrainController = class {
4037
4035
  _armed = false;
4038
4036
  _locked = false;
@@ -4158,9 +4156,20 @@ var DrainController = class {
4158
4156
  if (next !== void 0) this._defer.set(h.lease.stream, next);
4159
4157
  }
4160
4158
  if (this._defer.size > 0) this._defer.schedule();
4161
- if (acked.length) this._deps.on_acked(acked);
4162
- if (blocked.length) this._deps.on_blocked(blocked);
4163
- if (closeable.length) await this._deps.on_close(closeable);
4159
+ if (acked.length)
4160
+ contain(this._deps.logger, "acked", () => this._deps.on_acked(acked));
4161
+ if (blocked.length)
4162
+ contain(
4163
+ this._deps.logger,
4164
+ "blocked",
4165
+ () => this._deps.on_blocked(blocked)
4166
+ );
4167
+ if (closeable.length)
4168
+ await contain_async(
4169
+ this._deps.logger,
4170
+ "close",
4171
+ () => this._deps.on_close(closeable)
4172
+ );
4164
4173
  const has_errors = handled.some(({ error }) => error);
4165
4174
  if (!acked.length && !blocked.length && !has_errors) this._armed = false;
4166
4175
  return { fetched, leased, acked, blocked };