ResourcePool<T> class

A bounded, reusing pool of at most maxSize resources of type T.

Constructors

ResourcePool({required ResourceFactory<T> create, required int maxSize, ResourceDisposer<T>? onDispose})
Creates a pool that lazily builds up to maxSize resources via create, optionally disposing idle ones through onDispose when close drains the pool. maxSize must be at least 1. Audited: 2026-06-12 11:26 EDT

Properties

hashCode int
The hash code for this object.
no setterinherited
idleCount int
Resources free for immediate reuse. Audited: 2026-06-12 11:26 EDT
no setter
inUseCount int
Resources currently borrowed (created but not idle). Audited: 2026-06-12 11:26 EDT
no setter
maxSize int
Maximum number of resources that may exist (idle + in use) at once.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
waitingCount int
Borrowers currently waiting for a resource. Audited: 2026-06-12 11:26 EDT
no setter

Methods

acquire() Future<T>
Acquires a resource: reuses an idle one, else creates a new one if below maxSize, else waits FIFO for a release. Prefer use so the matching release can't be forgotten. Throws StateError if the pool is closed. Audited: 2026-06-12 11:26 EDT
close() Future<void>
Closes the pool: disposes every idle resource, fails every waiting borrower with StateError, and blocks new acquisitions. Awaits all idle disposals. Resources still checked out are NOT disposed by the pool — return them before closing (or dispose them yourself); a late release just drops the reference from the count. Audited: 2026-06-12 11:26 EDT
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
release(T resource) → void
Returns resource to the pool. A waiting borrower (if any) receives it directly; otherwise it becomes idle. After close, the resource is simply dropped from the count (not disposed here — see close). Audited: 2026-06-12 11:26 EDT
toString() String
A string representation of this object.
override
use<R>(Future<R> action(T resource)) Future<R>
Borrows a resource for action, returning it to the pool afterward even if action throws. The usual entry point — it pairs acquire/release so a resource can never leak. Throws StateError if the pool is closed. Audited: 2026-06-12 11:26 EDT

Operators

operator ==(Object other) bool
The equality operator.
inherited