@ultimat3/core 22.10.0 → 22.12.0

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/lifecycle.ts +7 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/core",
3
- "version": "22.10.0",
3
+ "version": "22.12.0",
4
4
  "description": "Ultimate's foundation: errors, context, env, config, clock, ids, logging, telemetry, lifecycle",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -40,6 +40,6 @@
40
40
  "test": "bun test"
41
41
  },
42
42
  "dependencies": {
43
- "@ultimat3/schema": "22.10.0"
43
+ "@ultimat3/schema": "22.12.0"
44
44
  }
45
45
  }
package/src/lifecycle.ts CHANGED
@@ -115,6 +115,8 @@ let log: Logger = rootLogger;
115
115
  let state: HealthState = 'starting';
116
116
  let startedAtMono = clock.monotonic();
117
117
  let inflight = 0;
118
+ /** Bumped by `resetLifecycle()`: a `beginWork()` finisher only ever counts down its own lifetime. */
119
+ let lifetime = 0;
118
120
  let registrations: Registration[] = [];
119
121
  let drainPromise: Promise<void> | undefined;
120
122
  let idleWaiters: (() => void)[] = [];
@@ -281,9 +283,13 @@ export function onShutdown(
281
283
  export function beginWork(): () => void {
282
284
  inflight += 1;
283
285
  let done = false;
286
+ const born = lifetime;
284
287
  return () => {
285
288
  if (done) return;
286
289
  done = true;
290
+ // One from before `resetLifecycle()` drove the fresh count to -1, and the drain's in-flight
291
+ // wait (idle only at exactly 0) then sat out its whole budget.
292
+ if (born !== lifetime) return;
287
293
  inflight -= 1;
288
294
  if (inflight === 0) {
289
295
  const waiters = idleWaiters;
@@ -486,6 +492,7 @@ export function resetLifecycle(): void {
486
492
  state = 'starting';
487
493
  startedAtMono = clock.monotonic();
488
494
  inflight = 0;
495
+ lifetime += 1;
489
496
  registrations = [];
490
497
  drainPromise = undefined;
491
498
  idleWaiters = [];