@orkestrel/pool 0.0.14 → 0.0.16

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @orkestrel/pool
2
2
 
3
3
  > A typed resource pool with optional bounded capacity, a warm floor, bounded loss recovery,
4
- > unique ownership, FIFO settlement, validated reuse, caller-owned cancellation, and explicit cleanup.
4
+ > exclusive leases by default, FIFO settlement, validated idle reuse, caller-owned cancellation, and explicit cleanup.
5
5
 
6
6
  Create a pool with the `createPool` function, hand it the hooks that make, check, and tear
7
7
  down one resource, and `await pool.acquire()` wherever the work needs one. Release the token
@@ -10,7 +10,7 @@ Environment-agnostic — no I/O, no browser or server assumptions. Part of the `
10
10
  line.
11
11
 
12
12
  For eager resources, set `min` and the required `restarts` bound on failed refills and losses
13
- of never-leased records between strike resets, then call `start()`.
13
+ of idle records between strike resets, then call `start()`.
14
14
  The `watch(value, signal)` hook reports loss; a holder can also call its token's `destroy()`.
15
15
  The pool disposes lost records before replacing them and keeps a record whose cleanup fails
16
16
  counted against `max`.
@@ -57,18 +57,18 @@ function isPoolError(value) {
57
57
  //#endregion
58
58
  //#region src/core/validators.ts
59
59
  /**
60
- * Tests whether a value is a positive safe integer, the only valid explicit pool maximum.
60
+ * Tests whether a value is a positive safe integer for a pool record or lease limit.
61
61
  *
62
- * @param value - The unknown maximum candidate
62
+ * @param value - The unknown record or lease limit candidate
63
63
  * @returns True if the value is a positive safe integer; false otherwise
64
64
  *
65
65
  * @example
66
66
  * ```ts
67
- * isPoolMax(8) // true
68
- * isPoolMax(Infinity) // false
67
+ * isPoolLimit(8) // true
68
+ * isPoolLimit(Infinity) // false
69
69
  * ```
70
70
  */
71
- function isPoolMax(value) {
71
+ function isPoolLimit(value) {
72
72
  return (0, _orkestrel_contract.isNumber)(value) && Number.isSafeInteger(value) && value > 0;
73
73
  }
74
74
  /**
@@ -120,12 +120,13 @@ var Pool = class {
120
120
  #destroy;
121
121
  #validate;
122
122
  #max;
123
+ #capacity;
123
124
  #min;
124
125
  #restarts;
125
126
  #watch;
126
127
  #error;
127
128
  #watches = /* @__PURE__ */ new Map();
128
- #used = /* @__PURE__ */ new WeakSet();
129
+ #births = /* @__PURE__ */ new WeakMap();
129
130
  #settled = /* @__PURE__ */ new WeakSet();
130
131
  #survivors = /* @__PURE__ */ new Map();
131
132
  #owing = /* @__PURE__ */ new Set();
@@ -133,7 +134,7 @@ var Pool = class {
133
134
  #resources = /* @__PURE__ */ new Map();
134
135
  #available = [];
135
136
  #validating = /* @__PURE__ */ new Set();
136
- #leased = /* @__PURE__ */ new Set();
137
+ #leased = /* @__PURE__ */ new Map();
137
138
  #destroying = /* @__PURE__ */ new Map();
138
139
  #waiters = [];
139
140
  #assigned = /* @__PURE__ */ new Set();
@@ -150,26 +151,32 @@ var Pool = class {
150
151
  #starting;
151
152
  #refilling = false;
152
153
  #strikes = 0;
154
+ #epoch = {};
153
155
  #owed = 0;
154
156
  #cause;
155
157
  /**
156
158
  * Constructs a pool and synchronously validates its capacity contract.
157
159
  *
158
160
  * @param options - Resource hooks, observation hooks, capacity, and optional bounded warm floor
159
- * @throws {@link PoolError} Thrown with `code: 'invalid'` when `min` or `max` is not a positive
160
- * safe integer, their explicit values differ, `restarts` is absent with `min`, present without
161
+ * @throws {@link PoolError} Thrown with `code: 'invalid'` when `capacity`, `min`, or `max` is not a positive
162
+ * safe integer, explicit `min` and `max` differ, `restarts` is absent with `min`, present without
161
163
  * `min`, or not a non-negative safe integer, or `watch` is not callable.
162
164
  */
163
165
  constructor(options) {
164
166
  const max = options.max;
167
+ const capacity = options.capacity;
165
168
  const min = options.min;
166
169
  const restarts = options.restarts;
167
170
  const watch = options.watch;
168
- if (max !== void 0 && !isPoolMax(max)) throw new PoolError({
171
+ if (max !== void 0 && !isPoolLimit(max)) throw new PoolError({
169
172
  code: "invalid",
170
173
  context: { value: max }
171
174
  });
172
- if (min !== void 0 && (!isPoolMax(min) || max !== void 0 && min !== max)) throw new PoolError({
175
+ if (capacity !== void 0 && !isPoolLimit(capacity)) throw new PoolError({
176
+ code: "invalid",
177
+ context: { value: capacity }
178
+ });
179
+ if (min !== void 0 && (!isPoolLimit(min) || max !== void 0 && min !== max)) throw new PoolError({
173
180
  code: "invalid",
174
181
  context: { value: min }
175
182
  });
@@ -187,6 +194,7 @@ var Pool = class {
187
194
  this.#destroy = options.destroy;
188
195
  this.#validate = options.validate;
189
196
  this.#max = max ?? min;
197
+ this.#capacity = capacity ?? 1;
190
198
  this.#min = min;
191
199
  this.#restarts = restarts;
192
200
  this.#watch = watch;
@@ -204,11 +212,11 @@ var Pool = class {
204
212
  get size() {
205
213
  return this.#resources.size;
206
214
  }
207
- /** Counts the records immediately available without validation work. */
215
+ /** Counts available records with no live lease or pending handout. */
208
216
  get idle() {
209
217
  return this.#available.length;
210
218
  }
211
- /** Counts the records represented by unsettled released-once lease tokens. */
219
+ /** Counts records with live leases, counting a shared record once rather than counting its leases. */
212
220
  get active() {
213
221
  return this.#leased.size;
214
222
  }
@@ -232,8 +240,8 @@ var Pool = class {
232
240
  return starting.promise;
233
241
  }
234
242
  /**
235
- * Queues the caller in FIFO order, validates an idle record or waits for a floor refill, and
236
- * creates on demand only without a floor.
243
+ * Queues the caller in FIFO order, shares an occupied record or validates an idle record, and
244
+ * waits for a floor refill or creates on demand without a floor.
237
245
  *
238
246
  * @param signal - Optional native cancellation signal
239
247
  * @returns A promise for the unique resource lease
@@ -241,9 +249,9 @@ var Pool = class {
241
249
  * with `code: 'invalid'`. This throw is synchronous rather than a rejected promise, so a caller
242
250
  * that handles failures with `.catch()` alone misses it.
243
251
  * @throws {@link PoolError} Thrown as a rejection when `destroy()` has already begun, with
244
- * `code: 'destroyed'`; when the create hook fails or the floor is spent without an idle record,
252
+ * `code: 'destroyed'`; when the create hook fails or the floor is spent without an eligible record,
245
253
  * with `code: 'create'` and the last cause; and when an invalid record's cleanup fails or
246
- * a floor retains a record, owns `min` records, has nothing idle, and has no refill or disposal
254
+ * a floor retains a record, owns `min` records, has nothing eligible, and has no refill or disposal
247
255
  * pending, even with live leases, with `code: 'cleanup'` and the retained cleanup failure as cause.
248
256
  * A `signal` that aborts rejects with the caller's exact `signal.reason` instead.
249
257
  */
@@ -348,8 +356,7 @@ var Pool = class {
348
356
  });
349
357
  }
350
358
  }
351
- #token(record, value) {
352
- const lease = {};
359
+ #token(record, value, lease) {
353
360
  return {
354
361
  value,
355
362
  release: this.#createRelease(record, lease),
@@ -360,7 +367,7 @@ var Pool = class {
360
367
  return () => {
361
368
  if (this.#settled.has(lease)) return;
362
369
  this.#settled.add(lease);
363
- this.#release(record);
370
+ this.#release(record, lease);
364
371
  };
365
372
  }
366
373
  #createDestroy(record, lease) {
@@ -405,10 +412,12 @@ var Pool = class {
405
412
  this.#repump = false;
406
413
  for (const waiter of this.#waiters) {
407
414
  if (this.#assigned.has(waiter) || this.#ready.has(waiter)) continue;
408
- const record = this.#available.shift();
415
+ const record = this.#select();
409
416
  if (record !== void 0) {
410
417
  this.#assigned.add(waiter);
411
- this.#validating.add(record);
418
+ const index = this.#available.indexOf(record);
419
+ if (index >= 0) this.#available.splice(index, 1);
420
+ if (this.#occupancy(record) === 0) this.#validating.add(record);
412
421
  this.#startValidation(waiter, record);
413
422
  continue;
414
423
  }
@@ -449,6 +458,25 @@ var Pool = class {
449
458
  this.#pumping = false;
450
459
  this.#fill();
451
460
  }
461
+ #occupancy(record) {
462
+ let count = this.#leased.get(record)?.size ?? 0;
463
+ for (const result of this.#ready.values()) if (result.success && result.record === record) count += 1;
464
+ return count;
465
+ }
466
+ #select() {
467
+ let selected;
468
+ let least = this.#capacity;
469
+ for (const record of this.#resources.keys()) {
470
+ if (this.#validating.has(record) || this.#destroying.has(record) || this.#survivors.has(record)) continue;
471
+ const count = this.#occupancy(record);
472
+ if (count === 0 && !this.#available.includes(record)) continue;
473
+ if (count < least) {
474
+ selected = record;
475
+ least = count;
476
+ }
477
+ }
478
+ return this.#available[0] ?? selected;
479
+ }
452
480
  #spent() {
453
481
  return this.#restarts !== void 0 && this.#strikes > this.#restarts;
454
482
  }
@@ -485,8 +513,7 @@ var Pool = class {
485
513
  try {
486
514
  value = await this.#create();
487
515
  } catch (error) {
488
- this.#strikes += 1;
489
- this.#cause = error;
516
+ this.#addStrike(error);
490
517
  return;
491
518
  }
492
519
  const record = this.#insert(value);
@@ -494,6 +521,7 @@ var Pool = class {
494
521
  }
495
522
  #insert(value) {
496
523
  const record = {};
524
+ this.#births.set(record, this.#epoch);
497
525
  this.#resources.set(record, value);
498
526
  if (this.#watch !== void 0) {
499
527
  const controller = new AbortController();
@@ -521,10 +549,12 @@ var Pool = class {
521
549
  this.#pump();
522
550
  }
523
551
  #strike(record, cause) {
524
- if (this.#min !== void 0 && !this.#used.has(record)) {
525
- this.#strikes += 1;
526
- this.#cause = cause;
527
- }
552
+ if (this.#min !== void 0 && !this.#leased.has(record)) this.#addStrike(cause);
553
+ }
554
+ #addStrike(cause) {
555
+ this.#strikes += 1;
556
+ this.#cause = cause;
557
+ this.#epoch = {};
528
558
  }
529
559
  #startCreate(waiter) {
530
560
  const operation = Promise.resolve().then(() => this.#createResource(waiter));
@@ -534,7 +564,7 @@ var Pool = class {
534
564
  #startValidation(waiter, record) {
535
565
  for (const [owned, value] of this.#resources) {
536
566
  if (owned !== record) continue;
537
- if (this.#validate === void 0) {
567
+ if (!this.#validating.has(record) || this.#validate === void 0) {
538
568
  this.#validating.delete(record);
539
569
  this.#prepare(waiter, record, value);
540
570
  return;
@@ -582,7 +612,7 @@ var Pool = class {
582
612
  this.#ready.set(waiter, {
583
613
  success: true,
584
614
  record,
585
- token: this.#token(record, value)
615
+ token: this.#token(record, value, waiter)
586
616
  });
587
617
  this.#commit();
588
618
  }
@@ -650,7 +680,7 @@ var Pool = class {
650
680
  this.#ready.set(waiter, {
651
681
  success: true,
652
682
  record,
653
- token: this.#token(record, value)
683
+ token: this.#token(record, value, waiter)
654
684
  });
655
685
  this.#commit();
656
686
  }
@@ -675,9 +705,10 @@ var Pool = class {
675
705
  waiter.reject(result.error);
676
706
  continue;
677
707
  }
678
- this.#leased.add(result.record);
679
- this.#used.add(result.record);
680
- this.#strikes = 0;
708
+ const leases = this.#leased.get(result.record) ?? /* @__PURE__ */ new Set();
709
+ leases.add(waiter);
710
+ this.#leased.set(result.record, leases);
711
+ if (this.#births.get(result.record) === this.#epoch) this.#strikes = 0;
681
712
  waiter.resolve(result.token);
682
713
  this.#emitter.emit("acquire");
683
714
  }
@@ -703,8 +734,10 @@ var Pool = class {
703
734
  this.#pump();
704
735
  this.#finish();
705
736
  }
706
- #release(record) {
707
- if (!this.#leased.delete(record)) return;
737
+ #release(record, lease) {
738
+ const leases = this.#leased.get(record);
739
+ if (leases === void 0 || !leases.delete(lease)) return;
740
+ if (leases.size === 0) this.#leased.delete(record);
708
741
  this.#recycle(record);
709
742
  }
710
743
  #recycle(record) {
@@ -713,7 +746,7 @@ var Pool = class {
713
746
  this.#own(this.#dispose(record));
714
747
  return;
715
748
  }
716
- this.#available.push(record);
749
+ if (this.#occupancy(record) === 0 && !this.#validating.has(record) && !this.#available.includes(record)) this.#available.push(record);
717
750
  this.#pump();
718
751
  if (this.#available.includes(record)) this.#emitter.emit("release");
719
752
  }
@@ -817,7 +850,7 @@ var Pool = class {
817
850
  //#region src/core/factories.ts
818
851
  /**
819
852
  * Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded
820
- * capacity, unique ownership, and FIFO settlement.
853
+ * capacity, exclusive leases by default, and FIFO settlement.
821
854
  *
822
855
  * @remarks
823
856
  * Concurrent create and validation hooks may overlap, while acquire promises settle in
@@ -861,7 +894,7 @@ exports.Pool = Pool;
861
894
  exports.PoolError = PoolError;
862
895
  exports.createPool = createPool;
863
896
  exports.isPoolError = isPoolError;
864
- exports.isPoolMax = isPoolMax;
897
+ exports.isPoolLimit = isPoolLimit;
865
898
  exports.isPoolSignal = isPoolSignal;
866
899
 
867
900
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["isError","isString","isInstance","isNumber","holds","isFunction","isNumber","isFunction","Emitter","attempt"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\nimport { isError, isInstance, isString } from '@orkestrel/contract'\n\n/**\n * Represents a stable, machine-readable pool failure that retains the original thrown value as\n * its cause without unsafe coercion, alongside structured context.\n *\n * @example\n * ```ts\n * import { PoolError, isPoolError } from '@orkestrel/pool'\n *\n * try {\n * \tawait pool.acquire()\n * } catch (error: unknown) {\n * \tif (isPoolError(error)) console.error(error.code, error.cause)\n * }\n * ```\n */\nexport class PoolError extends Error {\n\t/** Holds the stable machine-readable failure category. */\n\treadonly code\n\t/** Holds optional structured input or aggregate destroy-hook failure details. */\n\treadonly context\n\n\t/**\n\t * Creates a pool failure without coercing a hostile thrown value.\n\t *\n\t * @param options - Stable code plus optional cause and structured context\n\t */\n\tconstructor(options: PoolErrorOptions) {\n\t\tlet message = 'pool input is invalid'\n\t\tif (options.code === 'destroyed') message = 'pool is destroyed'\n\t\tif (options.code === 'create') message = 'pool create failed'\n\t\tif (options.code === 'cleanup') message = 'pool cleanup failed'\n\t\tif (\n\t\t\tisError(options.cause) &&\n\t\t\tisString(options.cause.message) &&\n\t\t\toptions.cause.message.length > 0\n\t\t) {\n\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t}\n\t\tsuper(message, options.cause === undefined ? undefined : { cause: options.cause })\n\t\tthis.name = 'PoolError'\n\t\tthis.code = options.code\n\t\tthis.context = options.context\n\t}\n}\n\n/**\n * Tests whether an unknown value is a {@link PoolError}, returning `false` for hostile proxies.\n *\n * @param value - The unknown boundary value\n * @returns True if the value is a real `PoolError` instance; false otherwise\n *\n * @example\n * ```ts\n * isPoolError(new PoolError({ code: 'destroyed' })) // true\n * isPoolError(new Error('other')) // false\n * ```\n */\nexport function isPoolError(value: unknown): value is PoolError {\n\treturn isInstance(value, PoolError)\n}\n","import { holds, isFunction, isNumber } from '@orkestrel/contract'\n\n/**\n * Tests whether a value is a positive safe integer, the only valid explicit pool maximum.\n *\n * @param value - The unknown maximum candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolMax(8) // true\n * isPoolMax(Infinity) // false\n * ```\n */\nexport function isPoolMax(value: unknown): value is number {\n\treturn isNumber(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`\n * for hostile proxies.\n *\n * @param value - The unknown signal candidate\n * @returns True if the value is a native `AbortSignal`; false otherwise\n *\n * @example\n * ```ts\n * isPoolSignal(new AbortController().signal) // true\n * isPoolSignal({ aborted: false }) // false\n * ```\n */\nexport function isPoolSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (!isFunction(getter)) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n","import type { EmitterErrorHandler, EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { attempt, isFunction, isNumber } from '@orkestrel/contract'\nimport { PoolError } from './errors.js'\nimport { isPoolMax, isPoolSignal } from './validators.js'\n\n/**\n * Represents a resource pool with optional bounded capacity and a warm floor, whose opaque\n * ownership records preserve FIFO settlement, cancellation, exact lease release, and\n * deterministic teardown under concurrent hooks.\n *\n * @typeParam T - The pooled resource value\n *\n * @example\n * ```ts\n * import { Pool } from '@orkestrel/pool'\n *\n * const pool = new Pool({ create: () => new Uint8Array(64), max: 2 })\n * const token = await pool.acquire()\n * try {\n * \tconsume(token.value)\n * } finally {\n * \ttoken.release()\n * }\n * await pool.destroy()\n * ```\n */\nexport class Pool<T> implements PoolInterface<T> {\n\treadonly #create: () => Promise<T> | T\n\treadonly #destroy: ((value: T) => Promise<void> | void) | undefined\n\treadonly #validate: ((value: T) => Promise<boolean> | boolean) | undefined\n\treadonly #max: number | undefined\n\treadonly #min: number | undefined\n\treadonly #restarts: number | undefined\n\treadonly #watch: PoolOptions<T>['watch']\n\treadonly #error: EmitterErrorHandler | undefined\n\treadonly #watches = new Map<object, AbortController>()\n\treadonly #used = new WeakSet<object>()\n\treadonly #settled = new WeakSet<object>()\n\treadonly #survivors = new Map<object, unknown>()\n\treadonly #owing = new Set<object>()\n\treadonly #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new Set<object>()\n\treadonly #destroying = new Map<object, Promise<void>>()\n\treadonly #waiters: Array<PromiseWithResolvers<PoolToken<T>>> = []\n\treadonly #assigned = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #reservations = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #signals = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t{ readonly signal: AbortSignal; readonly listener: () => void }\n\t>()\n\treadonly #ready = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t| { readonly success: true; readonly record: object; readonly token: PoolToken<T> }\n\t\t| { readonly success: false; readonly error: unknown }\n\t>()\n\treadonly #operations = new Set<Promise<void>>()\n\treadonly #owned = new Set<Promise<void>>()\n\treadonly #failures: unknown[] = []\n\t#ending: PromiseWithResolvers<void> | undefined\n\t#pumping = false\n\t#repump = false\n\t#started = false\n\t#starting: PromiseWithResolvers<void> | undefined\n\t#refilling = false\n\t#strikes = 0\n\t#owed = 0\n\t#cause: unknown\n\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, capacity, and optional bounded warm floor\n\t * @throws {@link PoolError} Thrown with `code: 'invalid'` when `min` or `max` is not a positive\n\t * safe integer, their explicit values differ, `restarts` is absent with `min`, present without\n\t * `min`, or not a non-negative safe integer, or `watch` is not callable.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tconst min = options.min\n\t\tconst restarts = options.restarts\n\t\tconst watch = options.watch\n\t\tif (max !== undefined && !isPoolMax(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\n\t\t}\n\t\tif (min !== undefined && (!isPoolMax(min) || (max !== undefined && min !== max))) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: min } })\n\t\t}\n\t\tif (\n\t\t\t(min !== undefined && restarts === undefined) ||\n\t\t\t(restarts !== undefined &&\n\t\t\t\t(min === undefined ||\n\t\t\t\t\t!isNumber(restarts) ||\n\t\t\t\t\t!Number.isSafeInteger(restarts) ||\n\t\t\t\t\trestarts < 0))\n\t\t) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: restarts } })\n\t\t}\n\t\tif (watch !== undefined && !isFunction(watch)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: watch } })\n\t\t}\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#create = options.create\n\t\tthis.#destroy = options.destroy\n\t\tthis.#validate = options.validate\n\t\tthis.#max = max ?? min\n\t\tthis.#min = min\n\t\tthis.#restarts = restarts\n\t\tthis.#watch = watch\n\t\tthis.#error = error\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\t/** Holds the typed synchronous lifecycle observation surface. */\n\tget emitter(): EmitterInterface<PoolEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Counts all owned records, including records validating, destroying, or retained after failed cleanup. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts the records immediately available without validation work. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts the records represented by unsettled released-once lease tokens. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Fills the warm floor and resets the strikes of a spent floor; without a floor, resolves immediately.\n\t *\n\t * @returns A promise that resolves when the floor owns `min` live records\n\t * @throws {@link PoolError} Thrown as a rejection with `code: 'create'` and the last cause\n\t * when the bound is spent, `code: 'cleanup'` when retained failed cleanup prevents filling,\n\t * or `code: 'destroyed'` when teardown begins.\n\t */\n\tstart(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (this.#min === undefined) return Promise.resolve()\n\t\tif (this.#starting !== undefined) return this.#starting.promise\n\t\tconst starting = Promise.withResolvers<void>()\n\t\tthis.#starting = starting\n\t\tthis.#started = true\n\t\tif (this.#spent()) this.#strikes = 0\n\t\tthis.#pump()\n\t\treturn starting.promise\n\t}\n\n\t/**\n\t * Queues the caller in FIFO order, validates an idle record or waits for a floor refill, and\n\t * creates on demand only without a floor.\n\t *\n\t * @param signal - Optional native cancellation signal\n\t * @returns A promise for the unique resource lease\n\t * @throws {@link PoolError} Thrown when `signal` is present and is not a native `AbortSignal`,\n\t * with `code: 'invalid'`. This throw is synchronous rather than a rejected promise, so a caller\n\t * that handles failures with `.catch()` alone misses it.\n\t * @throws {@link PoolError} Thrown as a rejection when `destroy()` has already begun, with\n\t * `code: 'destroyed'`; when the create hook fails or the floor is spent without an idle record,\n\t * with `code: 'create'` and the last cause; and when an invalid record's cleanup fails or\n\t * a floor retains a record, owns `min` records, has nothing idle, and has no refill or disposal\n\t * pending, even with live leases, with `code: 'cleanup'` and the retained cleanup failure as cause.\n\t * A `signal` that aborts rejects with the caller's exact `signal.reason` instead.\n\t */\n\tacquire(signal?: AbortSignal): Promise<PoolToken<T>> {\n\t\tif (signal !== undefined && !isPoolSignal(signal)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (signal !== undefined) {\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) return Promise.reject(state[1])\n\t\t}\n\n\t\tconst waiter = Promise.withResolvers<PoolToken<T>>()\n\t\tthis.#waiters.push(waiter)\n\t\tif (signal !== undefined) {\n\t\t\tconst listener = this.#createAbort(waiter, signal)\n\t\t\tAbortSignal.prototype.addEventListener.call(signal, 'abort', listener, { once: true })\n\t\t\tthis.#signals.set(waiter, { signal, listener })\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) this.#abort(waiter, state[1])\n\t\t}\n\t\tthis.#pump()\n\t\treturn waiter.promise\n\t}\n\n\t/**\n\t * Destroys the records that are idle at this call's synchronous snapshot and restores a started floor.\n\t *\n\t * @returns A promise that settles after every snapshot cleanup attempt\n\t * @throws {@link PoolError} Thrown when `destroy()` has already begun, with `code: 'destroyed'`.\n\t * @throws {@link PoolError} Thrown when a claimed record's destroy hook fails, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. Each arrives as a rejected\n\t * promise rather than a synchronous throw.\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tconst records = this.#available.splice(0)\n\t\tconst cleanups: Array<Promise<void>> = []\n\t\tfor (const record of records) {\n\t\t\tconst cleanup = this.#dispose(record)\n\t\t\tcleanups.push(cleanup)\n\t\t\tvoid cleanup.then(\n\t\t\t\t() => this.#pump(),\n\t\t\t\t() => this.#pump(),\n\t\t\t)\n\t\t}\n\t\treturn this.#settleClear(cleanups)\n\t}\n\n\t/**\n\t * Tears down the pool permanently and returns its stable completion barrier.\n\t *\n\t * @returns The exact promise shared by every destroy call\n\t * @throws {@link PoolError} Thrown when a destroy hook failure was retained or occurred during teardown, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. The barrier rejects; it\n\t * never throws synchronously, and a repeat call receives the same rejected promise.\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#ending !== undefined) return this.#ending.promise\n\n\t\tconst ending = Promise.withResolvers<void>()\n\t\tthis.#ending = ending\n\t\tthis.#starting?.reject(new PoolError({ code: 'destroyed' }))\n\t\tthis.#starting = undefined\n\t\tconst waiters = this.#waiters.splice(0)\n\t\tfor (const waiter of waiters) {\n\t\t\tthis.#detach(waiter)\n\t\t\twaiter.reject(new PoolError({ code: 'destroyed' }))\n\t\t}\n\t\tthis.#ready.clear()\n\t\tthis.#assigned.clear()\n\t\tthis.#available.splice(0)\n\t\tfor (const cleanup of this.#destroying.values()) this.#own(cleanup)\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (!this.#validating.has(record)) this.#own(this.#dispose(record))\n\t\t}\n\t\tthis.#finish()\n\t\treturn ending.promise\n\t}\n\n\t#createAbort(waiter: PromiseWithResolvers<PoolToken<T>>, signal: AbortSignal): () => void {\n\t\treturn (): void => {\n\t\t\tlet reason: unknown\n\t\t\ttry {\n\t\t\t\treason = this.#state(signal)[1]\n\t\t\t} catch (error: unknown) {\n\t\t\t\treason = error\n\t\t\t}\n\t\t\tthis.#abort(waiter, reason)\n\t\t}\n\t}\n\n\t#state(signal: AbortSignal): readonly [aborted: boolean, reason: unknown] {\n\t\tconst aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tconst reason = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'reason')?.get\n\t\tif (aborted === undefined || reason === undefined) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\ttry {\n\t\t\tconst stopped = Reflect.apply(aborted, signal, []) === true\n\t\t\treturn [stopped, stopped ? Reflect.apply(reason, signal, []) : undefined]\n\t\t} catch (error: unknown) {\n\t\t\tthrow new PoolError({ code: 'invalid', cause: error, context: { value: signal } })\n\t\t}\n\t}\n\n\t#token(record: object, value: T): PoolToken<T> {\n\t\tconst lease = {}\n\t\treturn {\n\t\t\tvalue,\n\t\t\trelease: this.#createRelease(record, lease),\n\t\t\tdestroy: this.#createDestroy(record, lease),\n\t\t}\n\t}\n\n\t#createRelease(record: object, lease: object): () => void {\n\t\treturn (): void => {\n\t\t\tif (this.#settled.has(lease)) return\n\t\t\tthis.#settled.add(lease)\n\t\t\tthis.#release(record)\n\t\t}\n\t}\n\n\t#createDestroy(record: object, lease: object): () => Promise<void> {\n\t\treturn (): Promise<void> => {\n\t\t\tif (this.#settled.has(lease)) return Promise.resolve()\n\t\t\tthis.#settled.add(lease)\n\t\t\treturn (this.#destroying.get(record) ?? this.#lose(record)).catch((error: unknown) => {\n\t\t\t\tthrow new PoolError({ code: 'cleanup', cause: error })\n\t\t\t})\n\t\t}\n\t}\n\n\t#abort(waiter: PromiseWithResolvers<PoolToken<T>>, reason: unknown): void {\n\t\tconst index = this.#waiters.indexOf(waiter)\n\t\tif (index < 0) return\n\t\tthis.#waiters.splice(index, 1)\n\t\tthis.#detach(waiter)\n\t\tconst ready = this.#ready.get(waiter)\n\t\tthis.#ready.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (ready?.success === true) {\n\t\t\tthis.#recycle(ready.record)\n\t\t}\n\t\twaiter.reject(reason)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t}\n\n\t#detach(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst entry = this.#signals.get(waiter)\n\t\tif (entry === undefined) return\n\t\tAbortSignal.prototype.removeEventListener.call(entry.signal, 'abort', entry.listener)\n\t\tthis.#signals.delete(waiter)\n\t}\n\n\t#pump(): void {\n\t\tif (this.#ending !== undefined) return\n\t\tif (this.#pumping) {\n\t\t\tthis.#repump = true\n\t\t\treturn\n\t\t}\n\n\t\tthis.#pumping = true\n\t\tdo {\n\t\t\tthis.#repump = false\n\t\t\tfor (const waiter of this.#waiters) {\n\t\t\t\tif (this.#assigned.has(waiter) || this.#ready.has(waiter)) continue\n\t\t\t\tconst record = this.#available.shift()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#validating.add(record)\n\t\t\t\t\tthis.#startValidation(waiter, record)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (this.#min !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#resources.size >= this.#min &&\n\t\t\t\t\t\tthis.#survivors.size > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({\n\t\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\t\tcause: this.#survivors.values().next().value,\n\t\t\t\t\t\t\t\tcontext: { failures: [...this.#failures] },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.#spent() &&\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#owed === 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({ code: 'create', cause: this.#cause }),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif (this.#max === undefined || this.#resources.size + this.#reservations.size < this.#max) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#reservations.add(waiter)\n\t\t\t\t\tthis.#startCreate(waiter)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t} while (this.#repump)\n\t\tthis.#pumping = false\n\t\tthis.#fill()\n\t}\n\n\t#spent(): boolean {\n\t\treturn this.#restarts !== undefined && this.#strikes > this.#restarts\n\t}\n\n\t#fill(): void {\n\t\tif (this.#ending !== undefined || !this.#started || this.#min === undefined) return\n\t\tif (this.#refilling) return\n\t\tconst live = this.#resources.size - this.#destroying.size - this.#survivors.size\n\t\tif (live >= this.#min) {\n\t\t\tthis.#starting?.resolve()\n\t\t\tthis.#starting = undefined\n\t\t}\n\t\tif (this.#resources.size < this.#min && (!this.#spent() || this.#owed > 0)) {\n\t\t\tif (this.#owed > 0) this.#owed -= 1\n\t\t\tthis.#refilling = true\n\t\t\tconst operation = Promise.resolve().then(() => this.#refill())\n\t\t\tthis.#operations.add(operation)\n\t\t\t// Refill never rejects: create failures are caught, and watch/emitter callbacks isolate errors.\n\t\t\tvoid operation.then(() => {\n\t\t\t\tthis.#refilling = false\n\t\t\t\tthis.#completeOperation(operation)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t\tif (this.#destroying.size > 0) return\n\t\tif (this.#spent() || this.#survivors.size > 0) {\n\t\t\tthis.#starting?.reject(\n\t\t\t\tthis.#spent()\n\t\t\t\t\t? new PoolError({ code: 'create', cause: this.#cause })\n\t\t\t\t\t: this.#cleanupError(this.#failures),\n\t\t\t)\n\t\t\tthis.#starting = undefined\n\t\t}\n\t}\n\n\tasync #refill(): Promise<void> {\n\t\tif (this.#ending !== undefined) return\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#strikes += 1\n\t\t\tthis.#cause = error\n\t\t\treturn\n\t\t}\n\t\tconst record = this.#insert(value)\n\t\tthis.#recycle(record)\n\t}\n\n\t#insert(value: T): object {\n\t\tconst record = {}\n\t\tthis.#resources.set(record, value)\n\t\tif (this.#watch !== undefined) {\n\t\t\tconst controller = new AbortController()\n\t\t\tthis.#watches.set(record, controller)\n\t\t\tconst watching = attempt(() => this.#watch?.(value, controller.signal))\n\t\t\tconst settled = watching.success\n\t\t\t\t? Promise.resolve(watching.value)\n\t\t\t\t: Promise.reject(watching.error)\n\t\t\tvoid settled.then(\n\t\t\t\t() => this.#own(this.#lose(record)),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (controller.signal.aborted) return\n\t\t\t\t\tthis.#own(this.#lose(record, error))\n\t\t\t\t\tattempt(() => this.#error?.(error, 'watch'))\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tthis.#emitter.emit('create')\n\t\treturn record\n\t}\n\n\tasync #lose(record: object, cause?: unknown): Promise<void> {\n\t\tif (\n\t\t\tthis.#ending !== undefined ||\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t)\n\t\t\treturn\n\t\tif (this.#leased.has(record) && this.#min !== undefined) this.#owing.add(record)\n\t\tthis.#strike(record, cause)\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#pump()\n\t\t\tthrow error\n\t\t}\n\t\tthis.#pump()\n\t}\n\n\t#strike(record: object, cause?: unknown): void {\n\t\tif (this.#min !== undefined && !this.#used.has(record)) {\n\t\t\tthis.#strikes += 1\n\t\t\tthis.#cause = cause\n\t\t}\n\t}\n\n\t#startCreate(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst operation = Promise.resolve().then(() => this.#createResource(waiter))\n\t\tthis.#operations.add(operation)\n\t\tvoid operation.then(\n\t\t\t() => this.#completeOperation(operation),\n\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'create'),\n\t\t)\n\t}\n\n\t#startValidation(waiter: PromiseWithResolvers<PoolToken<T>>, record: object): void {\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tif (this.#validate === undefined) {\n\t\t\t\tthis.#validating.delete(record)\n\t\t\t\tthis.#prepare(waiter, record, value)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst operation = Promise.resolve().then(() => this.#validateResource(waiter, record, value))\n\t\t\tthis.#operations.add(operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => this.#completeOperation(operation),\n\t\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'invalid'),\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.#validating.delete(record)\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#repump = true\n\t}\n\n\tasync #createResource(waiter: PromiseWithResolvers<PoolToken<T>>): Promise<void> {\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#reservations.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'create', cause: error }),\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t\treturn\n\t\t}\n\n\t\tthis.#reservations.delete(waiter)\n\t\tconst record = this.#insert(value)\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\tasync #validateResource(\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\trecord: object,\n\t\tvalue: T,\n\t): Promise<void> {\n\t\tlet valid = false\n\t\ttry {\n\t\t\tvalid = (await this.#validate?.(value)) === true\n\t\t} catch {}\n\t\tthis.#validating.delete(record)\n\t\tif (\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!valid) this.#strike(record)\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (valid) this.#recycle(record)\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#dispose(record)\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthis.#record(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (valid) {\n\t\t\tthis.#prepare(waiter, record, value)\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'cleanup', cause: error }),\n\t\t\t\t})\n\t\t\t\tthis.#commit()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#record(error)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#pump()\n\t}\n\n\t#prepare(waiter: PromiseWithResolvers<PoolToken<T>>, record: object, value: T): void {\n\t\tif (!this.#waiters.includes(waiter) || this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\t#commit(): void {\n\t\twhile (this.#ending === undefined) {\n\t\t\tconst waiter = this.#waiters[0]\n\t\t\tif (waiter === undefined) return\n\t\t\tconst result = this.#ready.get(waiter)\n\t\t\tif (result === undefined) return\n\t\t\tif (\n\t\t\t\tresult.success &&\n\t\t\t\t(!this.#resources.has(result.record) ||\n\t\t\t\t\tthis.#destroying.has(result.record) ||\n\t\t\t\t\tthis.#survivors.has(result.record))\n\t\t\t) {\n\t\t\t\tthis.#ready.delete(waiter)\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t\tthis.#repump = true\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#waiters.shift()\n\t\t\tthis.#repump = true\n\t\t\tthis.#ready.delete(waiter)\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#detach(waiter)\n\t\t\tif (!result.success) {\n\t\t\t\twaiter.reject(result.error)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tthis.#leased.add(result.record)\n\t\t\tthis.#used.add(result.record)\n\t\t\tthis.#strikes = 0\n\t\t\twaiter.resolve(result.token)\n\t\t\tthis.#emitter.emit('acquire')\n\t\t}\n\t}\n\n\t#completeOperation(operation: Promise<void>): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#failOperation(\n\t\toperation: Promise<void>,\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\terror: unknown,\n\t\tcode: PoolCode,\n\t): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#reservations.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (this.#waiters.includes(waiter)) {\n\t\t\tthis.#ready.set(waiter, { success: false, error: new PoolError({ code, cause: error }) })\n\t\t}\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#release(record: object): void {\n\t\tif (!this.#leased.delete(record)) return\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record))\n\t\t\treturn\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tthis.#available.push(record)\n\t\tthis.#pump()\n\t\tif (this.#available.includes(record)) this.#emitter.emit('release')\n\t}\n\n\t#dispose(record: object): Promise<void> {\n\t\tif (this.#survivors.has(record)) return Promise.resolve()\n\t\tconst existing = this.#destroying.get(record)\n\t\tif (existing !== undefined) return existing\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tconst cleanup = Promise.withResolvers<void>()\n\t\t\tthis.#destroying.set(record, cleanup.promise)\n\t\t\tconst index = this.#available.indexOf(record)\n\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\tthis.#validating.delete(record)\n\t\t\tthis.#leased.delete(record)\n\t\t\tthis.#watches.get(record)?.abort()\n\t\t\tthis.#watches.delete(record)\n\t\t\tif (this.#ending !== undefined) this.#own(cleanup.promise)\n\t\t\tvoid this.#clean(record, value, cleanup)\n\t\t\treturn cleanup.promise\n\t\t}\n\t\treturn Promise.resolve()\n\t}\n\n\tasync #clean(record: object, value: T, cleanup: PromiseWithResolvers<void>): Promise<void> {\n\t\tlet disposal: Promise<void>\n\t\ttry {\n\t\t\tdisposal = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tdisposal = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait disposal\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tif (failed && this.#min !== undefined) {\n\t\t\tthis.#survivors.set(record, failure)\n\t\t\tthis.#record(failure)\n\t\t} else {\n\t\t\tthis.#resources.delete(record)\n\t\t\tif (this.#owing.has(record)) this.#owed += 1\n\t\t}\n\t\tthis.#owing.delete(record)\n\t\tif (failed) cleanup.reject(failure)\n\t\telse cleanup.resolve()\n\t\t// Cleanup owners must bind outcomes before destroy observers can reenter.\n\t\tawait Promise.resolve()\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#destroying.delete(record)\n\t\tif (this.#min !== undefined) this.#pump()\n\t\tthis.#finish()\n\t}\n\n\tasync #settleClear(cleanups: ReadonlyArray<Promise<void>>): Promise<void> {\n\t\tconst settled = await Promise.allSettled(cleanups)\n\t\tconst failures: unknown[] = []\n\t\tfor (const result of settled) {\n\t\t\tif (\n\t\t\t\tresult.status === 'rejected' &&\n\t\t\t\t!failures.some((failure) => Object.is(failure, result.reason))\n\t\t\t) {\n\t\t\t\tfailures.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (failures.length > 0) throw this.#cleanupError(failures)\n\t}\n\n\t#own(cleanup: Promise<void>): void {\n\t\tif (this.#owned.has(cleanup)) return\n\t\tthis.#owned.add(cleanup)\n\t\tvoid cleanup.then(\n\t\t\t() => this.#completeCleanup(cleanup),\n\t\t\t(error: unknown) => this.#failCleanup(cleanup, error),\n\t\t)\n\t}\n\n\t#completeCleanup(cleanup: Promise<void>): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#finish()\n\t}\n\n\t#failCleanup(cleanup: Promise<void>, error: unknown): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#record(error)\n\t\tthis.#finish()\n\t}\n\n\t#record(error: unknown): void {\n\t\tif (!this.#failures.some((failure) => Object.is(failure, error))) this.#failures.push(error)\n\t}\n\n\t#cleanupError(failures: readonly unknown[]): PoolError {\n\t\treturn new PoolError({\n\t\t\tcode: 'cleanup',\n\t\t\t...(failures[0] === undefined ? {} : { cause: failures[0] }),\n\t\t\tcontext: { failures: [...failures] },\n\t\t})\n\t}\n\n\t#finish(): void {\n\t\tconst ending = this.#ending\n\t\tif (ending === undefined || this.#operations.size > 0 || this.#owned.size > 0) return\n\t\tlet claimed = false\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return\n\t\tthis.#emitter.destroy()\n\t\tif (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures))\n\t\telse ending.resolve()\n\t}\n}\n","import type { PoolInterface, PoolOptions } from './types.js'\nimport { Pool } from './Pool.js'\n\n/**\n * Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded\n * capacity, unique ownership, and FIFO settlement.\n *\n * @remarks\n * Concurrent create and validation hooks may overlap, while acquire promises settle in\n * request order. `clear` owns its idle snapshot; `destroy` returns one stable barrier and\n * waits for every in-flight create, validation, and destroy attempt before destroying the\n * emitter last.\n * Set `min` with its required `restarts` bound and call `start()` to warm resources and\n * refill losses independently of queued acquires. `watch` observes loss and its signal\n * aborts at disposal; a token can declare loss through `destroy()`.\n *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, capacity, optional bounded warm floor, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown with `code: 'invalid'` when capacity, restart bounds, or\n * the watch hook are invalid. Construction validates them synchronously, before the pool exists.\n *\n * @example Create a pool\n * ```ts\n * import { createPool } from '@orkestrel/pool'\n *\n * const pool = createPool<Connection>({\n * \tcreate: () => connect(),\n * \tdestroy: (connection) => connection.close(),\n * \tvalidate: (connection) => connection.alive,\n * \tmax: 8,\n * })\n *\n * const token = await pool.acquire()\n * try {\n * \tawait token.value.query('select 1')\n * } finally {\n * \ttoken.release()\n * }\n * ```\n */\nexport function createPool<T>(options: PoolOptions<T>): PoolInterface<T> {\n\treturn new Pool(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,YAAb,cAA+B,MAAM;;CAEpC;;CAEA;;;;;;CAOA,YAAY,SAA2B;EACtC,IAAI,UAAU;EACd,IAAI,QAAQ,SAAS,aAAa,UAAU;EAC5C,IAAI,QAAQ,S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;;;;;;;;AC3xBA,SAAgB,WAAc,SAA2C;CACxE,OAAO,IAAI,KAAK,OAAO;AACxB"}
1
+ {"version":3,"file":"index.cjs","names":["isError","isString","isInstance","isNumber","holds","isFunction","isNumber","isFunction","Emitter","attempt"],"sources":["../../../src/core/errors.ts","../../../src/core/validators.ts","../../../src/core/Pool.ts","../../../src/core/factories.ts"],"sourcesContent":["import type { PoolErrorOptions } from './types.js'\nimport { isError, isInstance, isString } from '@orkestrel/contract'\n\n/**\n * Represents a stable, machine-readable pool failure that retains the original thrown value as\n * its cause without unsafe coercion, alongside structured context.\n *\n * @example\n * ```ts\n * import { PoolError, isPoolError } from '@orkestrel/pool'\n *\n * try {\n * \tawait pool.acquire()\n * } catch (error: unknown) {\n * \tif (isPoolError(error)) console.error(error.code, error.cause)\n * }\n * ```\n */\nexport class PoolError extends Error {\n\t/** Holds the stable machine-readable failure category. */\n\treadonly code\n\t/** Holds optional structured input or aggregate destroy-hook failure details. */\n\treadonly context\n\n\t/**\n\t * Creates a pool failure without coercing a hostile thrown value.\n\t *\n\t * @param options - Stable code plus optional cause and structured context\n\t */\n\tconstructor(options: PoolErrorOptions) {\n\t\tlet message = 'pool input is invalid'\n\t\tif (options.code === 'destroyed') message = 'pool is destroyed'\n\t\tif (options.code === 'create') message = 'pool create failed'\n\t\tif (options.code === 'cleanup') message = 'pool cleanup failed'\n\t\tif (\n\t\t\tisError(options.cause) &&\n\t\t\tisString(options.cause.message) &&\n\t\t\toptions.cause.message.length > 0\n\t\t) {\n\t\t\tmessage = `${message}: ${options.cause.message}`\n\t\t}\n\t\tsuper(message, options.cause === undefined ? undefined : { cause: options.cause })\n\t\tthis.name = 'PoolError'\n\t\tthis.code = options.code\n\t\tthis.context = options.context\n\t}\n}\n\n/**\n * Tests whether an unknown value is a {@link PoolError}, returning `false` for hostile proxies.\n *\n * @param value - The unknown boundary value\n * @returns True if the value is a real `PoolError` instance; false otherwise\n *\n * @example\n * ```ts\n * isPoolError(new PoolError({ code: 'destroyed' })) // true\n * isPoolError(new Error('other')) // false\n * ```\n */\nexport function isPoolError(value: unknown): value is PoolError {\n\treturn isInstance(value, PoolError)\n}\n","import { holds, isFunction, isNumber } from '@orkestrel/contract'\n\n/**\n * Tests whether a value is a positive safe integer for a pool record or lease limit.\n *\n * @param value - The unknown record or lease limit candidate\n * @returns True if the value is a positive safe integer; false otherwise\n *\n * @example\n * ```ts\n * isPoolLimit(8) // true\n * isPoolLimit(Infinity) // false\n * ```\n */\nexport function isPoolLimit(value: unknown): value is number {\n\treturn isNumber(value) && Number.isSafeInteger(value) && value > 0\n}\n\n/**\n * Tests whether a value is a native `AbortSignal` for the acquire boundary, returning `false`\n * for hostile proxies.\n *\n * @param value - The unknown signal candidate\n * @returns True if the value is a native `AbortSignal`; false otherwise\n *\n * @example\n * ```ts\n * isPoolSignal(new AbortController().signal) // true\n * isPoolSignal({ aborted: false }) // false\n * ```\n */\nexport function isPoolSignal(value: unknown): value is AbortSignal {\n\treturn holds(() => {\n\t\tconst getter = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tif (!isFunction(getter)) return false\n\t\tReflect.apply(getter, value, [])\n\t\treturn true\n\t})\n}\n","import type { EmitterErrorHandler, EmitterInterface } from '@orkestrel/emitter'\nimport type { PoolCode, PoolEventMap, PoolInterface, PoolOptions, PoolToken } from './types.js'\nimport { Emitter } from '@orkestrel/emitter'\nimport { attempt, isFunction, isNumber } from '@orkestrel/contract'\nimport { PoolError } from './errors.js'\nimport { isPoolLimit, isPoolSignal } from './validators.js'\n\n/**\n * Represents a resource pool with optional bounded capacity and a warm floor, whose opaque\n * ownership records preserve FIFO settlement, cancellation, exact lease release, and\n * deterministic teardown under concurrent hooks.\n *\n * @typeParam T - The pooled resource value\n *\n * @example\n * ```ts\n * import { Pool } from '@orkestrel/pool'\n *\n * const pool = new Pool({ create: () => new Uint8Array(64), max: 2 })\n * const token = await pool.acquire()\n * try {\n * \tconsume(token.value)\n * } finally {\n * \ttoken.release()\n * }\n * await pool.destroy()\n * ```\n */\nexport class Pool<T> implements PoolInterface<T> {\n\treadonly #create: () => Promise<T> | T\n\treadonly #destroy: ((value: T) => Promise<void> | void) | undefined\n\treadonly #validate: ((value: T) => Promise<boolean> | boolean) | undefined\n\treadonly #max: number | undefined\n\treadonly #capacity: number\n\treadonly #min: number | undefined\n\treadonly #restarts: number | undefined\n\treadonly #watch: PoolOptions<T>['watch']\n\treadonly #error: EmitterErrorHandler | undefined\n\treadonly #watches = new Map<object, AbortController>()\n\treadonly #births = new WeakMap<object, object>()\n\treadonly #settled = new WeakSet<object>()\n\treadonly #survivors = new Map<object, unknown>()\n\treadonly #owing = new Set<object>()\n\treadonly #emitter: Emitter<PoolEventMap>\n\treadonly #resources = new Map<object, T>()\n\treadonly #available: object[] = []\n\treadonly #validating = new Set<object>()\n\treadonly #leased = new Map<object, Set<object>>()\n\treadonly #destroying = new Map<object, Promise<void>>()\n\treadonly #waiters: Array<PromiseWithResolvers<PoolToken<T>>> = []\n\treadonly #assigned = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #reservations = new Set<PromiseWithResolvers<PoolToken<T>>>()\n\treadonly #signals = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t{ readonly signal: AbortSignal; readonly listener: () => void }\n\t>()\n\treadonly #ready = new Map<\n\t\tPromiseWithResolvers<PoolToken<T>>,\n\t\t| { readonly success: true; readonly record: object; readonly token: PoolToken<T> }\n\t\t| { readonly success: false; readonly error: unknown }\n\t>()\n\treadonly #operations = new Set<Promise<void>>()\n\treadonly #owned = new Set<Promise<void>>()\n\treadonly #failures: unknown[] = []\n\t#ending: PromiseWithResolvers<void> | undefined\n\t#pumping = false\n\t#repump = false\n\t#started = false\n\t#starting: PromiseWithResolvers<void> | undefined\n\t#refilling = false\n\t#strikes = 0\n\t#epoch = {}\n\t#owed = 0\n\t#cause: unknown\n\n\t/**\n\t * Constructs a pool and synchronously validates its capacity contract.\n\t *\n\t * @param options - Resource hooks, observation hooks, capacity, and optional bounded warm floor\n\t * @throws {@link PoolError} Thrown with `code: 'invalid'` when `capacity`, `min`, or `max` is not a positive\n\t * safe integer, explicit `min` and `max` differ, `restarts` is absent with `min`, present without\n\t * `min`, or not a non-negative safe integer, or `watch` is not callable.\n\t */\n\tconstructor(options: PoolOptions<T>) {\n\t\tconst max = options.max\n\t\tconst capacity = options.capacity\n\t\tconst min = options.min\n\t\tconst restarts = options.restarts\n\t\tconst watch = options.watch\n\t\tif (max !== undefined && !isPoolLimit(max)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: max } })\n\t\t}\n\t\tif (capacity !== undefined && !isPoolLimit(capacity)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: capacity } })\n\t\t}\n\t\tif (min !== undefined && (!isPoolLimit(min) || (max !== undefined && min !== max))) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: min } })\n\t\t}\n\t\tif (\n\t\t\t(min !== undefined && restarts === undefined) ||\n\t\t\t(restarts !== undefined &&\n\t\t\t\t(min === undefined ||\n\t\t\t\t\t!isNumber(restarts) ||\n\t\t\t\t\t!Number.isSafeInteger(restarts) ||\n\t\t\t\t\trestarts < 0))\n\t\t) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: restarts } })\n\t\t}\n\t\tif (watch !== undefined && !isFunction(watch)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: watch } })\n\t\t}\n\t\tconst on = options.on\n\t\tconst error = options.error\n\t\tthis.#create = options.create\n\t\tthis.#destroy = options.destroy\n\t\tthis.#validate = options.validate\n\t\tthis.#max = max ?? min\n\t\tthis.#capacity = capacity ?? 1\n\t\tthis.#min = min\n\t\tthis.#restarts = restarts\n\t\tthis.#watch = watch\n\t\tthis.#error = error\n\t\tthis.#emitter = new Emitter({\n\t\t\t...(on === undefined ? {} : { on }),\n\t\t\t...(error === undefined ? {} : { error }),\n\t\t})\n\t}\n\n\t/** Holds the typed synchronous lifecycle observation surface. */\n\tget emitter(): EmitterInterface<PoolEventMap> {\n\t\treturn this.#emitter\n\t}\n\n\t/** Counts all owned records, including records validating, destroying, or retained after failed cleanup. */\n\tget size(): number {\n\t\treturn this.#resources.size\n\t}\n\n\t/** Counts available records with no live lease or pending handout. */\n\tget idle(): number {\n\t\treturn this.#available.length\n\t}\n\n\t/** Counts records with live leases, counting a shared record once rather than counting its leases. */\n\tget active(): number {\n\t\treturn this.#leased.size\n\t}\n\n\t/**\n\t * Fills the warm floor and resets the strikes of a spent floor; without a floor, resolves immediately.\n\t *\n\t * @returns A promise that resolves when the floor owns `min` live records\n\t * @throws {@link PoolError} Thrown as a rejection with `code: 'create'` and the last cause\n\t * when the bound is spent, `code: 'cleanup'` when retained failed cleanup prevents filling,\n\t * or `code: 'destroyed'` when teardown begins.\n\t */\n\tstart(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (this.#min === undefined) return Promise.resolve()\n\t\tif (this.#starting !== undefined) return this.#starting.promise\n\t\tconst starting = Promise.withResolvers<void>()\n\t\tthis.#starting = starting\n\t\tthis.#started = true\n\t\tif (this.#spent()) this.#strikes = 0\n\t\tthis.#pump()\n\t\treturn starting.promise\n\t}\n\n\t/**\n\t * Queues the caller in FIFO order, shares an occupied record or validates an idle record, and\n\t * waits for a floor refill or creates on demand without a floor.\n\t *\n\t * @param signal - Optional native cancellation signal\n\t * @returns A promise for the unique resource lease\n\t * @throws {@link PoolError} Thrown when `signal` is present and is not a native `AbortSignal`,\n\t * with `code: 'invalid'`. This throw is synchronous rather than a rejected promise, so a caller\n\t * that handles failures with `.catch()` alone misses it.\n\t * @throws {@link PoolError} Thrown as a rejection when `destroy()` has already begun, with\n\t * `code: 'destroyed'`; when the create hook fails or the floor is spent without an eligible record,\n\t * with `code: 'create'` and the last cause; and when an invalid record's cleanup fails or\n\t * a floor retains a record, owns `min` records, has nothing eligible, and has no refill or disposal\n\t * pending, even with live leases, with `code: 'cleanup'` and the retained cleanup failure as cause.\n\t * A `signal` that aborts rejects with the caller's exact `signal.reason` instead.\n\t */\n\tacquire(signal?: AbortSignal): Promise<PoolToken<T>> {\n\t\tif (signal !== undefined && !isPoolSignal(signal)) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tif (signal !== undefined) {\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) return Promise.reject(state[1])\n\t\t}\n\n\t\tconst waiter = Promise.withResolvers<PoolToken<T>>()\n\t\tthis.#waiters.push(waiter)\n\t\tif (signal !== undefined) {\n\t\t\tconst listener = this.#createAbort(waiter, signal)\n\t\t\tAbortSignal.prototype.addEventListener.call(signal, 'abort', listener, { once: true })\n\t\t\tthis.#signals.set(waiter, { signal, listener })\n\t\t\tconst state = this.#state(signal)\n\t\t\tif (state[0]) this.#abort(waiter, state[1])\n\t\t}\n\t\tthis.#pump()\n\t\treturn waiter.promise\n\t}\n\n\t/**\n\t * Destroys the records that are idle at this call's synchronous snapshot and restores a started floor.\n\t *\n\t * @returns A promise that settles after every snapshot cleanup attempt\n\t * @throws {@link PoolError} Thrown when `destroy()` has already begun, with `code: 'destroyed'`.\n\t * @throws {@link PoolError} Thrown when a claimed record's destroy hook fails, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. Each arrives as a rejected\n\t * promise rather than a synchronous throw.\n\t */\n\tclear(): Promise<void> {\n\t\tif (this.#ending !== undefined) return Promise.reject(new PoolError({ code: 'destroyed' }))\n\t\tconst records = this.#available.splice(0)\n\t\tconst cleanups: Array<Promise<void>> = []\n\t\tfor (const record of records) {\n\t\t\tconst cleanup = this.#dispose(record)\n\t\t\tcleanups.push(cleanup)\n\t\t\tvoid cleanup.then(\n\t\t\t\t() => this.#pump(),\n\t\t\t\t() => this.#pump(),\n\t\t\t)\n\t\t}\n\t\treturn this.#settleClear(cleanups)\n\t}\n\n\t/**\n\t * Tears down the pool permanently and returns its stable completion barrier.\n\t *\n\t * @returns The exact promise shared by every destroy call\n\t * @throws {@link PoolError} Thrown when a destroy hook failure was retained or occurred during teardown, with\n\t * `code: 'cleanup'` and every distinct failure in `context.failures`. The barrier rejects; it\n\t * never throws synchronously, and a repeat call receives the same rejected promise.\n\t */\n\tdestroy(): Promise<void> {\n\t\tif (this.#ending !== undefined) return this.#ending.promise\n\n\t\tconst ending = Promise.withResolvers<void>()\n\t\tthis.#ending = ending\n\t\tthis.#starting?.reject(new PoolError({ code: 'destroyed' }))\n\t\tthis.#starting = undefined\n\t\tconst waiters = this.#waiters.splice(0)\n\t\tfor (const waiter of waiters) {\n\t\t\tthis.#detach(waiter)\n\t\t\twaiter.reject(new PoolError({ code: 'destroyed' }))\n\t\t}\n\t\tthis.#ready.clear()\n\t\tthis.#assigned.clear()\n\t\tthis.#available.splice(0)\n\t\tfor (const cleanup of this.#destroying.values()) this.#own(cleanup)\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (!this.#validating.has(record)) this.#own(this.#dispose(record))\n\t\t}\n\t\tthis.#finish()\n\t\treturn ending.promise\n\t}\n\n\t#createAbort(waiter: PromiseWithResolvers<PoolToken<T>>, signal: AbortSignal): () => void {\n\t\treturn (): void => {\n\t\t\tlet reason: unknown\n\t\t\ttry {\n\t\t\t\treason = this.#state(signal)[1]\n\t\t\t} catch (error: unknown) {\n\t\t\t\treason = error\n\t\t\t}\n\t\t\tthis.#abort(waiter, reason)\n\t\t}\n\t}\n\n\t#state(signal: AbortSignal): readonly [aborted: boolean, reason: unknown] {\n\t\tconst aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted')?.get\n\t\tconst reason = Object.getOwnPropertyDescriptor(AbortSignal.prototype, 'reason')?.get\n\t\tif (aborted === undefined || reason === undefined) {\n\t\t\tthrow new PoolError({ code: 'invalid', context: { value: signal } })\n\t\t}\n\t\ttry {\n\t\t\tconst stopped = Reflect.apply(aborted, signal, []) === true\n\t\t\treturn [stopped, stopped ? Reflect.apply(reason, signal, []) : undefined]\n\t\t} catch (error: unknown) {\n\t\t\tthrow new PoolError({ code: 'invalid', cause: error, context: { value: signal } })\n\t\t}\n\t}\n\n\t#token(record: object, value: T, lease: object): PoolToken<T> {\n\t\treturn {\n\t\t\tvalue,\n\t\t\trelease: this.#createRelease(record, lease),\n\t\t\tdestroy: this.#createDestroy(record, lease),\n\t\t}\n\t}\n\n\t#createRelease(record: object, lease: object): () => void {\n\t\treturn (): void => {\n\t\t\tif (this.#settled.has(lease)) return\n\t\t\tthis.#settled.add(lease)\n\t\t\tthis.#release(record, lease)\n\t\t}\n\t}\n\n\t#createDestroy(record: object, lease: object): () => Promise<void> {\n\t\treturn (): Promise<void> => {\n\t\t\tif (this.#settled.has(lease)) return Promise.resolve()\n\t\t\tthis.#settled.add(lease)\n\t\t\treturn (this.#destroying.get(record) ?? this.#lose(record)).catch((error: unknown) => {\n\t\t\t\tthrow new PoolError({ code: 'cleanup', cause: error })\n\t\t\t})\n\t\t}\n\t}\n\n\t#abort(waiter: PromiseWithResolvers<PoolToken<T>>, reason: unknown): void {\n\t\tconst index = this.#waiters.indexOf(waiter)\n\t\tif (index < 0) return\n\t\tthis.#waiters.splice(index, 1)\n\t\tthis.#detach(waiter)\n\t\tconst ready = this.#ready.get(waiter)\n\t\tthis.#ready.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (ready?.success === true) {\n\t\t\tthis.#recycle(ready.record)\n\t\t}\n\t\twaiter.reject(reason)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t}\n\n\t#detach(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst entry = this.#signals.get(waiter)\n\t\tif (entry === undefined) return\n\t\tAbortSignal.prototype.removeEventListener.call(entry.signal, 'abort', entry.listener)\n\t\tthis.#signals.delete(waiter)\n\t}\n\n\t#pump(): void {\n\t\tif (this.#ending !== undefined) return\n\t\tif (this.#pumping) {\n\t\t\tthis.#repump = true\n\t\t\treturn\n\t\t}\n\n\t\tthis.#pumping = true\n\t\tdo {\n\t\t\tthis.#repump = false\n\t\t\tfor (const waiter of this.#waiters) {\n\t\t\t\tif (this.#assigned.has(waiter) || this.#ready.has(waiter)) continue\n\t\t\t\tconst record = this.#select()\n\t\t\t\tif (record !== undefined) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tconst index = this.#available.indexOf(record)\n\t\t\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\t\t\tif (this.#occupancy(record) === 0) this.#validating.add(record)\n\t\t\t\t\tthis.#startValidation(waiter, record)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (this.#min !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#resources.size >= this.#min &&\n\t\t\t\t\t\tthis.#survivors.size > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({\n\t\t\t\t\t\t\t\tcode: 'cleanup',\n\t\t\t\t\t\t\t\tcause: this.#survivors.values().next().value,\n\t\t\t\t\t\t\t\tcontext: { failures: [...this.#failures] },\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.#spent() &&\n\t\t\t\t\t\t!this.#refilling &&\n\t\t\t\t\t\tthis.#destroying.size === 0 &&\n\t\t\t\t\t\tthis.#owed === 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\t\t\tsuccess: false,\n\t\t\t\t\t\t\terror: new PoolError({ code: 'create', cause: this.#cause }),\n\t\t\t\t\t\t})\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tif (this.#max === undefined || this.#resources.size + this.#reservations.size < this.#max) {\n\t\t\t\t\tthis.#assigned.add(waiter)\n\t\t\t\t\tthis.#reservations.add(waiter)\n\t\t\t\t\tthis.#startCreate(waiter)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t} while (this.#repump)\n\t\tthis.#pumping = false\n\t\tthis.#fill()\n\t}\n\n\t#occupancy(record: object): number {\n\t\tlet count = this.#leased.get(record)?.size ?? 0\n\t\tfor (const result of this.#ready.values()) {\n\t\t\tif (result.success && result.record === record) count += 1\n\t\t}\n\t\treturn count\n\t}\n\n\t#select(): object | undefined {\n\t\tlet selected: object | undefined\n\t\tlet least = this.#capacity\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tconst count = this.#occupancy(record)\n\t\t\tif (count === 0 && !this.#available.includes(record)) continue\n\t\t\tif (count < least) {\n\t\t\t\tselected = record\n\t\t\t\tleast = count\n\t\t\t}\n\t\t}\n\t\treturn this.#available[0] ?? selected\n\t}\n\n\t#spent(): boolean {\n\t\treturn this.#restarts !== undefined && this.#strikes > this.#restarts\n\t}\n\n\t#fill(): void {\n\t\tif (this.#ending !== undefined || !this.#started || this.#min === undefined) return\n\t\tif (this.#refilling) return\n\t\tconst live = this.#resources.size - this.#destroying.size - this.#survivors.size\n\t\tif (live >= this.#min) {\n\t\t\tthis.#starting?.resolve()\n\t\t\tthis.#starting = undefined\n\t\t}\n\t\tif (this.#resources.size < this.#min && (!this.#spent() || this.#owed > 0)) {\n\t\t\tif (this.#owed > 0) this.#owed -= 1\n\t\t\tthis.#refilling = true\n\t\t\tconst operation = Promise.resolve().then(() => this.#refill())\n\t\t\tthis.#operations.add(operation)\n\t\t\t// Refill never rejects: create failures are caught, and watch/emitter callbacks isolate errors.\n\t\t\tvoid operation.then(() => {\n\t\t\t\tthis.#refilling = false\n\t\t\t\tthis.#completeOperation(operation)\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t\tif (this.#destroying.size > 0) return\n\t\tif (this.#spent() || this.#survivors.size > 0) {\n\t\t\tthis.#starting?.reject(\n\t\t\t\tthis.#spent()\n\t\t\t\t\t? new PoolError({ code: 'create', cause: this.#cause })\n\t\t\t\t\t: this.#cleanupError(this.#failures),\n\t\t\t)\n\t\t\tthis.#starting = undefined\n\t\t}\n\t}\n\n\tasync #refill(): Promise<void> {\n\t\tif (this.#ending !== undefined) return\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#addStrike(error)\n\t\t\treturn\n\t\t}\n\t\tconst record = this.#insert(value)\n\t\tthis.#recycle(record)\n\t}\n\n\t#insert(value: T): object {\n\t\tconst record = {}\n\t\tthis.#births.set(record, this.#epoch)\n\t\tthis.#resources.set(record, value)\n\t\tif (this.#watch !== undefined) {\n\t\t\tconst controller = new AbortController()\n\t\t\tthis.#watches.set(record, controller)\n\t\t\tconst watching = attempt(() => this.#watch?.(value, controller.signal))\n\t\t\tconst settled = watching.success\n\t\t\t\t? Promise.resolve(watching.value)\n\t\t\t\t: Promise.reject(watching.error)\n\t\t\tvoid settled.then(\n\t\t\t\t() => this.#own(this.#lose(record)),\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tif (controller.signal.aborted) return\n\t\t\t\t\tthis.#own(this.#lose(record, error))\n\t\t\t\t\tattempt(() => this.#error?.(error, 'watch'))\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t\tthis.#emitter.emit('create')\n\t\treturn record\n\t}\n\n\tasync #lose(record: object, cause?: unknown): Promise<void> {\n\t\tif (\n\t\t\tthis.#ending !== undefined ||\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t)\n\t\t\treturn\n\t\tif (this.#leased.has(record) && this.#min !== undefined) this.#owing.add(record)\n\t\tthis.#strike(record, cause)\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#pump()\n\t\t\tthrow error\n\t\t}\n\t\tthis.#pump()\n\t}\n\n\t#strike(record: object, cause?: unknown): void {\n\t\tif (this.#min !== undefined && !this.#leased.has(record)) {\n\t\t\tthis.#addStrike(cause)\n\t\t}\n\t}\n\n\t#addStrike(cause: unknown): void {\n\t\tthis.#strikes += 1\n\t\tthis.#cause = cause\n\t\tthis.#epoch = {}\n\t}\n\n\t#startCreate(waiter: PromiseWithResolvers<PoolToken<T>>): void {\n\t\tconst operation = Promise.resolve().then(() => this.#createResource(waiter))\n\t\tthis.#operations.add(operation)\n\t\tvoid operation.then(\n\t\t\t() => this.#completeOperation(operation),\n\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'create'),\n\t\t)\n\t}\n\n\t#startValidation(waiter: PromiseWithResolvers<PoolToken<T>>, record: object): void {\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tif (!this.#validating.has(record) || this.#validate === undefined) {\n\t\t\t\tthis.#validating.delete(record)\n\t\t\t\tthis.#prepare(waiter, record, value)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst operation = Promise.resolve().then(() => this.#validateResource(waiter, record, value))\n\t\t\tthis.#operations.add(operation)\n\t\t\tvoid operation.then(\n\t\t\t\t() => this.#completeOperation(operation),\n\t\t\t\t(error: unknown) => this.#failOperation(operation, waiter, error, 'invalid'),\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tthis.#validating.delete(record)\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#repump = true\n\t}\n\n\tasync #createResource(waiter: PromiseWithResolvers<PoolToken<T>>): Promise<void> {\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = await this.#create()\n\t\t} catch (error: unknown) {\n\t\t\tthis.#reservations.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'create', cause: error }),\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t}\n\t\t\tthis.#commit()\n\t\t\treturn\n\t\t}\n\n\t\tthis.#reservations.delete(waiter)\n\t\tconst record = this.#insert(value)\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\tasync #validateResource(\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\trecord: object,\n\t\tvalue: T,\n\t): Promise<void> {\n\t\tlet valid = false\n\t\ttry {\n\t\t\tvalid = (await this.#validate?.(value)) === true\n\t\t} catch {}\n\t\tthis.#validating.delete(record)\n\t\tif (\n\t\t\t!this.#resources.has(record) ||\n\t\t\tthis.#destroying.has(record) ||\n\t\t\tthis.#survivors.has(record)\n\t\t) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\ttry {\n\t\t\t\tawait this.#dispose(record)\n\t\t\t} catch {}\n\t\t\treturn\n\t\t}\n\t\tif (!valid) this.#strike(record)\n\t\tif (!this.#waiters.includes(waiter)) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (valid) this.#recycle(record)\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait this.#dispose(record)\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthis.#record(error)\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tif (valid) {\n\t\t\tthis.#prepare(waiter, record, value)\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.#dispose(record)\n\t\t} catch (error: unknown) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tif (this.#waiters.includes(waiter)) {\n\t\t\t\tthis.#ready.set(waiter, {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: new PoolError({ code: 'cleanup', cause: error }),\n\t\t\t\t})\n\t\t\t\tthis.#commit()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#record(error)\n\t\t\tthis.#pump()\n\t\t\treturn\n\t\t}\n\t\tthis.#assigned.delete(waiter)\n\t\tthis.#pump()\n\t}\n\n\t#prepare(waiter: PromiseWithResolvers<PoolToken<T>>, record: object, value: T): void {\n\t\tif (!this.#waiters.includes(waiter) || this.#ending !== undefined) {\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#recycle(record)\n\t\t\treturn\n\t\t}\n\t\tthis.#ready.set(waiter, {\n\t\t\tsuccess: true,\n\t\t\trecord,\n\t\t\ttoken: this.#token(record, value, waiter),\n\t\t})\n\t\tthis.#commit()\n\t}\n\n\t#commit(): void {\n\t\twhile (this.#ending === undefined) {\n\t\t\tconst waiter = this.#waiters[0]\n\t\t\tif (waiter === undefined) return\n\t\t\tconst result = this.#ready.get(waiter)\n\t\t\tif (result === undefined) return\n\t\t\tif (\n\t\t\t\tresult.success &&\n\t\t\t\t(!this.#resources.has(result.record) ||\n\t\t\t\t\tthis.#destroying.has(result.record) ||\n\t\t\t\t\tthis.#survivors.has(result.record))\n\t\t\t) {\n\t\t\t\tthis.#ready.delete(waiter)\n\t\t\t\tthis.#assigned.delete(waiter)\n\t\t\t\tthis.#repump = true\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.#waiters.shift()\n\t\t\tthis.#repump = true\n\t\t\tthis.#ready.delete(waiter)\n\t\t\tthis.#assigned.delete(waiter)\n\t\t\tthis.#detach(waiter)\n\t\t\tif (!result.success) {\n\t\t\t\twaiter.reject(result.error)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst leases = this.#leased.get(result.record) ?? new Set<object>()\n\t\t\tleases.add(waiter)\n\t\t\tthis.#leased.set(result.record, leases)\n\t\t\tif (this.#births.get(result.record) === this.#epoch) this.#strikes = 0\n\t\t\twaiter.resolve(result.token)\n\t\t\tthis.#emitter.emit('acquire')\n\t\t}\n\t}\n\n\t#completeOperation(operation: Promise<void>): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#failOperation(\n\t\toperation: Promise<void>,\n\t\twaiter: PromiseWithResolvers<PoolToken<T>>,\n\t\terror: unknown,\n\t\tcode: PoolCode,\n\t): void {\n\t\tthis.#operations.delete(operation)\n\t\tthis.#reservations.delete(waiter)\n\t\tthis.#assigned.delete(waiter)\n\t\tif (this.#waiters.includes(waiter)) {\n\t\t\tthis.#ready.set(waiter, { success: false, error: new PoolError({ code, cause: error }) })\n\t\t}\n\t\tthis.#commit()\n\t\tthis.#pump()\n\t\tthis.#finish()\n\t}\n\n\t#release(record: object, lease: object): void {\n\t\tconst leases = this.#leased.get(record)\n\t\tif (leases === undefined || !leases.delete(lease)) return\n\t\tif (leases.size === 0) this.#leased.delete(record)\n\t\tthis.#recycle(record)\n\t}\n\n\t#recycle(record: object): void {\n\t\tif (!this.#resources.has(record) || this.#destroying.has(record) || this.#survivors.has(record))\n\t\t\treturn\n\t\tif (this.#ending !== undefined) {\n\t\t\tthis.#own(this.#dispose(record))\n\t\t\treturn\n\t\t}\n\t\tif (\n\t\t\tthis.#occupancy(record) === 0 &&\n\t\t\t!this.#validating.has(record) &&\n\t\t\t!this.#available.includes(record)\n\t\t) {\n\t\t\tthis.#available.push(record)\n\t\t}\n\t\tthis.#pump()\n\t\tif (this.#available.includes(record)) this.#emitter.emit('release')\n\t}\n\n\t#dispose(record: object): Promise<void> {\n\t\tif (this.#survivors.has(record)) return Promise.resolve()\n\t\tconst existing = this.#destroying.get(record)\n\t\tif (existing !== undefined) return existing\n\t\tfor (const [owned, value] of this.#resources) {\n\t\t\tif (owned !== record) continue\n\t\t\tconst cleanup = Promise.withResolvers<void>()\n\t\t\tthis.#destroying.set(record, cleanup.promise)\n\t\t\tconst index = this.#available.indexOf(record)\n\t\t\tif (index >= 0) this.#available.splice(index, 1)\n\t\t\tthis.#validating.delete(record)\n\t\t\tthis.#leased.delete(record)\n\t\t\tthis.#watches.get(record)?.abort()\n\t\t\tthis.#watches.delete(record)\n\t\t\tif (this.#ending !== undefined) this.#own(cleanup.promise)\n\t\t\tvoid this.#clean(record, value, cleanup)\n\t\t\treturn cleanup.promise\n\t\t}\n\t\treturn Promise.resolve()\n\t}\n\n\tasync #clean(record: object, value: T, cleanup: PromiseWithResolvers<void>): Promise<void> {\n\t\tlet disposal: Promise<void>\n\t\ttry {\n\t\t\tdisposal = Promise.resolve(this.#destroy?.(value))\n\t\t} catch (error: unknown) {\n\t\t\tdisposal = Promise.reject(error)\n\t\t}\n\t\tlet failure: unknown\n\t\tlet failed = false\n\t\ttry {\n\t\t\tawait disposal\n\t\t} catch (error: unknown) {\n\t\t\tfailure = error\n\t\t\tfailed = true\n\t\t}\n\t\tif (failed && this.#min !== undefined) {\n\t\t\tthis.#survivors.set(record, failure)\n\t\t\tthis.#record(failure)\n\t\t} else {\n\t\t\tthis.#resources.delete(record)\n\t\t\tif (this.#owing.has(record)) this.#owed += 1\n\t\t}\n\t\tthis.#owing.delete(record)\n\t\tif (failed) cleanup.reject(failure)\n\t\telse cleanup.resolve()\n\t\t// Cleanup owners must bind outcomes before destroy observers can reenter.\n\t\tawait Promise.resolve()\n\t\tthis.#emitter.emit('destroy')\n\t\tthis.#destroying.delete(record)\n\t\tif (this.#min !== undefined) this.#pump()\n\t\tthis.#finish()\n\t}\n\n\tasync #settleClear(cleanups: ReadonlyArray<Promise<void>>): Promise<void> {\n\t\tconst settled = await Promise.allSettled(cleanups)\n\t\tconst failures: unknown[] = []\n\t\tfor (const result of settled) {\n\t\t\tif (\n\t\t\t\tresult.status === 'rejected' &&\n\t\t\t\t!failures.some((failure) => Object.is(failure, result.reason))\n\t\t\t) {\n\t\t\t\tfailures.push(result.reason)\n\t\t\t}\n\t\t}\n\t\tif (failures.length > 0) throw this.#cleanupError(failures)\n\t}\n\n\t#own(cleanup: Promise<void>): void {\n\t\tif (this.#owned.has(cleanup)) return\n\t\tthis.#owned.add(cleanup)\n\t\tvoid cleanup.then(\n\t\t\t() => this.#completeCleanup(cleanup),\n\t\t\t(error: unknown) => this.#failCleanup(cleanup, error),\n\t\t)\n\t}\n\n\t#completeCleanup(cleanup: Promise<void>): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#finish()\n\t}\n\n\t#failCleanup(cleanup: Promise<void>, error: unknown): void {\n\t\tthis.#owned.delete(cleanup)\n\t\tthis.#record(error)\n\t\tthis.#finish()\n\t}\n\n\t#record(error: unknown): void {\n\t\tif (!this.#failures.some((failure) => Object.is(failure, error))) this.#failures.push(error)\n\t}\n\n\t#cleanupError(failures: readonly unknown[]): PoolError {\n\t\treturn new PoolError({\n\t\t\tcode: 'cleanup',\n\t\t\t...(failures[0] === undefined ? {} : { cause: failures[0] }),\n\t\t\tcontext: { failures: [...failures] },\n\t\t})\n\t}\n\n\t#finish(): void {\n\t\tconst ending = this.#ending\n\t\tif (ending === undefined || this.#operations.size > 0 || this.#owned.size > 0) return\n\t\tlet claimed = false\n\t\tfor (const record of this.#resources.keys()) {\n\t\t\tif (\n\t\t\t\tthis.#validating.has(record) ||\n\t\t\t\tthis.#destroying.has(record) ||\n\t\t\t\tthis.#survivors.has(record)\n\t\t\t)\n\t\t\t\tcontinue\n\t\t\tclaimed = true\n\t\t\tthis.#own(this.#dispose(record))\n\t\t}\n\t\tif (claimed || this.#resources.size > this.#survivors.size || this.#destroying.size > 0) return\n\t\tthis.#emitter.destroy()\n\t\tif (this.#failures.length > 0) ending.reject(this.#cleanupError(this.#failures))\n\t\telse ending.resolve()\n\t}\n}\n","import type { PoolInterface, PoolOptions } from './types.js'\nimport { Pool } from './Pool.js'\n\n/**\n * Creates a distinct {@link PoolInterface} from resource lifecycle hooks, with optional bounded\n * capacity, exclusive leases by default, and FIFO settlement.\n *\n * @remarks\n * Concurrent create and validation hooks may overlap, while acquire promises settle in\n * request order. `clear` owns its idle snapshot; `destroy` returns one stable barrier and\n * waits for every in-flight create, validation, and destroy attempt before destroying the\n * emitter last.\n * Set `min` with its required `restarts` bound and call `start()` to warm resources and\n * refill losses independently of queued acquires. `watch` observes loss and its signal\n * aborts at disposal; a token can declare loss through `destroy()`.\n *\n * @typeParam T - The pooled resource type\n * @param options - Lifecycle hooks, capacity, optional bounded warm floor, and observation hooks\n * @returns A working {@link PoolInterface}\n * @throws {@link PoolError} Thrown with `code: 'invalid'` when capacity, restart bounds, or\n * the watch hook are invalid. Construction validates them synchronously, before the pool exists.\n *\n * @example Create a pool\n * ```ts\n * import { createPool } from '@orkestrel/pool'\n *\n * const pool = createPool<Connection>({\n * \tcreate: () => connect(),\n * \tdestroy: (connection) => connection.close(),\n * \tvalidate: (connection) => connection.alive,\n * \tmax: 8,\n * })\n *\n * const token = await pool.acquire()\n * try {\n * \tawait token.value.query('select 1')\n * } finally {\n * \ttoken.release()\n * }\n * ```\n */\nexport function createPool<T>(options: PoolOptions<T>): PoolInterface<T> {\n\treturn new Pool(options)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,YAAb,cAA+B,MAAM;;CAEpC;;CAEA;;;;;;CAOA,YAAY,SAA2B;EACtC,IAAI,UAAU;EACd,IAAI,QAAQ,SAAS,aAAa,UAAU;EAC5C,IAAI,QAAQ,SAAS,UAAU,UAAU;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