Pool<T> class
Constructors
-
Pool(int targetSize, FutureOr<
T> _createItem(), {Future<void> onRemoveItem(T)?, FutureOr<bool> checkIsLive(T)?, Duration checkIsLiveTimeout = const Duration(seconds: 10), FutureOr<void> onReturn(T)?, Duration onReturnTimeout = const Duration(seconds: 10), Duration? maxLifetime, int? maxQueueLength, Duration maintenanceInterval = const Duration(seconds: 30), bool autoRefill = false, void onChange()?})
Properties
- autoRefill → bool
-
Whether background maintenance refills the pool up to targetSize.
final
- available → int
-
no setter
- checkIsLiveTimeout → Duration
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isDisposed → bool
-
Whether dispose has been called.
no setter
- maintenanceInterval → Duration
-
Interval for background maintenance: idle items that exceeded
maxLifetime are evicted and, if autoRefill is set, the pool is
topped back up to targetSize.
final
- maxLifetime → Duration?
-
final
- maxQueueLength → int?
-
Maximum number of take requests waiting for an item at the same time.
final
- onChange → void Function()?
-
final
-
onRemoveItem
→ Future<
void> Function(T)? -
final
- onReturnTimeout → Duration
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- targetSize ↔ int
-
getter/setter pair
- total → int
-
no setter
Methods
-
adopt(
T item) → void -
Adds an externally created
itemto the pool. -
dispose(
) → Future< void> - Shuts down the pool.
-
fill(
) → Future< void> - Fills the pool up to targetSize by creating missing items in parallel.
-
give(
T item) → void -
Returns a previously taken
itemback to the pool. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
T item) → void -
take(
{Duration? timeout = const Duration(seconds: 30)}) → Future< T> - Takes an item from the pool.
-
toString(
) → String -
A string representation of this object.
inherited
-
use<
R> (FutureOr< R> delegate(T), {Duration? timeout}) → Future<R> - Takes an item from the pool and provides it to the delegate.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited