| Surface | Status | Notes |
|---|---|---|
createPool() |
Stable | Fixed-size pool factory with overload for "null". |
Pool methods |
Stable | acquire, release, drain, borrow, dispose. |
| Runtime state | Stable | available, alive, disposed. |
| Overflow strategies | Stable | "throw", "null", "grow", function handler. |
| Error classes | Stable | PoolError, PoolDisposedError. |
- Objects are created eagerly at construction.
createPool()validates before the firstcreate()call, in this order:size(a missing or non-object options argument fails here),onOverflow,createis a function,resetis a function.create()and a function overflow handler must return a value that is notnullorundefined. OtherwisePoolErroris thrown and nothing changes:createPool()returns no pool,"grow"discards the partial allocation, and the handler result is never added toalive.release()detects foreign/double release.drain()resets every live object.dispose()is idempotent and permanent.borrow()throwsPoolErrorsynchronously, after the disposed check and beforeacquire(), whenfnis not a function orsignallacksaddEventListener/removeEventListener; anullorundefinedsignal means no signal.borrow()releases infinallyfor sync throw, async rejection, and abort paths.- Misuse and overflow errors are
PoolError; every message starts withaipooljs:(argument errors readaipooljs: <subject> must be <constraint>), anderror.nameequals the class name. - Re-entrancy: the pool has no event dispatch and no mailbox.
create(),reset()and function overflow handlers run synchronously inside the pool call and may call back into the same pool; nested calls run immediately and are never queued. A re-entrantdispose()makes the in-progress call throwPoolDisposedError, anddrain()skips snapshot entries that a re-entrantreset()already released. Separate pools are independent.
- Throwing
reset()permanently removes that slot from the pool. - Function overflow handlers are caller-owned escape hatches and may alias live objects if misused.
- Abort does not cancel the work inside
borrow(). "grow"trades correctness for allocation spikes; use intentionally.