bulkhead

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package bulkhead provides a Bulkhead policy.

Index

Constants

This section is empty.

Variables

View Source
var ErrFull = errors.New("bulkhead full")

ErrFull 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 ErrFull 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.

func With

func With[R any](maxConcurrency uint) Bulkhead[R]

With returns a new Bulkhead for execution result type R and the maxConcurrency.

type BulkheadBuilder

type BulkheadBuilder[R any] interface {
	// WithMaxWaitTime configures the maxWaitTime to wait for permits to be available.
	WithMaxWaitTime(maxWaitTime time.Duration) BulkheadBuilder[R]

	// OnFull registers the listener to be called when the bulkhead is full.
	OnFull(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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL