Bulkhead class
Caps the number of concurrently in-flight Result-returning operations,
optionally queueing the overflow.
The bulkhead pattern isolates a slow or failing downstream so it cannot
exhaust client-side resources (threads, sockets, memory). Callers above
the configured concurrency wait in a FIFO queue; once the queue is also
full, additional callers receive
Error(Failure.bulkheadRejected()) instead of being kept waiting.
final bulkhead = Bulkhead(maxConcurrent: 8, maxQueueSize: 16);
final result = await bulkhead.execute(() => api.fetchUser(id));
// If the bulkhead is full, `result` is an Error with
// FailureKind.bulkheadRejected — the underlying call was not made.
Composes naturally with CircuitBreaker, RetryHelper, and ResultCache: wrap the bulkhead around the call to bound resource use, then layer retries / caching outside it as needed.
Constructors
Properties
- hasCapacity → bool
-
Whether a new call would be admitted right now without queueing or
rejection.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- inFlight → int
-
The number of operations currently executing.
no setter
- maxConcurrent → int
-
Maximum number of operations allowed to run at the same time.
final
- maxQueueSize → int
-
Maximum number of callers that may wait when maxConcurrent is reached.
0disables queueing, causing overflow callers to be rejected.final - queueLength → int
-
The number of callers currently waiting for a slot to open.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
execute<
T> (Future< Result< operation()) → Future<T> >Result< T> > -
Runs
operationsubject to the bulkhead's concurrency cap. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited