Documentation ¶
Overview ¶
Package bulkhead provides a Bulkhead policy.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBulkheadFull = errors.New("bulkhead full")
ErrBulkheadFull is returned when an execution is attempted against a Bulkhead that is full.
Functions ¶
This section is empty.
Types ¶
type Bulkhead ¶
type Bulkhead[R any] interface { failsafe.Policy[R] // AcquirePermit attempts to acquire a permit to perform an execution against within the Bulkhead, waiting until one is // available or the execution is canceled. Returns context.Canceled if the ctx is canceled. Callers should call // ReleasePermit to release a successfully acquired permit back to the Bulkhead. // // ctx may be nil. AcquirePermit(ctx context.Context) error // AcquirePermitWithMaxWait attempts to acquire a permit to perform an execution within the Bulkhead, waiting up to the // maxWaitTime until one is available or the ctx is canceled. Returns ErrBulkheadFull if a permit could not be acquired // in time. Returns context.Canceled if the ctx is canceled. Callers should call ReleasePermit to release a successfully // acquired permit back to the Bulkhead. // // ctx may be nil. AcquirePermitWithMaxWait(ctx context.Context, maxWaitTime time.Duration) error // ReleasePermit releases an execution permit back to the Bulkhead. ReleasePermit() // TryAcquirePermit tries to acquire a permit to perform an execution within the Bulkhead, returning immediately without // waiting. Returns true if the permit was acquired, else false. Callers should call ReleasePermit to release a // successfully acquired permit back to the Bulkhead. TryAcquirePermit() bool }
Bulkhead is a policy restricts concurrent executions as a way of preventing system overload.
This type is concurrency safe.
type BulkheadBuilder ¶
type BulkheadBuilder[R any] interface { // WithMaxWaitTime configures the maxWaitTime to wait for permits to be available. WithMaxWaitTime(maxWaitTime time.Duration) BulkheadBuilder[R] // OnBulkheadFull registers the listener to be called when the bulkhead is full. OnBulkheadFull(listener func(event failsafe.ExecutionEvent[R])) BulkheadBuilder[R] // Build returns a new Bulkhead using the builder's configuration. Build() Bulkhead[R] }
BulkheadBuilder builds Bulkhead instances.
This type is not concurrency safe.
func Builder ¶
func Builder[R any](maxConcurrency uint) BulkheadBuilder[R]
Builder returns a BulkheadBuilder for execution result type R which builds Timeouts for the timeoutDelay.
Click to show internal directories.
Click to hide internal directories.