async/resource_pool_utils library
Async resource pool with a fixed maximum size — roadmap #666.
Bounds how many expensive-to-create resources (DB connections, HTTP clients, worker isolates) exist at once and reuses idle ones instead of recreating them. A borrower acquires a resource, uses it, and returns it; when every resource is busy, further borrowers wait FIFO until one is released. Lazily grows up to the cap — a resource is created only when a borrower needs one and none is idle.
Classes
-
ResourcePool<
T> -
A bounded, reusing pool of at most maxSize resources of type
T.
Typedefs
-
ResourceDisposer<
T> = Future< void> Function(T resource) - Disposes a pooled resource (close a socket, end a connection).
-
ResourceFactory<
T> = Future< T> Function() - Creates a fresh pooled resource.