bulkhead

package
v0.92.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bulkhead provides per-capability semaphore isolation for ability invocations.

Index

Constants

This section is empty.

Variables

View Source
var ErrBulkheadFull = errors.New("bulkhead: queue full")

ErrBulkheadFull is returned when the queue is at capacity and a new request cannot be accepted.

View Source
var ErrBulkheadTimeout = errors.New("bulkhead: wait timeout")

ErrBulkheadTimeout is returned when a slot cannot be acquired within the configured timeout.

Functions

func SetDefaults

func SetDefaults(opts ...Option)

SetDefaults sets default options applied to all Bulkhead instances created via Get. Must be called before any Get calls for the settings to take effect.

Types

type Bulkhead

type Bulkhead struct {
	// contains filtered or unexported fields
}

Bulkhead controls concurrent access for a named resource.

func Get

func Get(name string) *Bulkhead

Get returns the Bulkhead for the given name, creating one with default config if needed.

func New

func New(name string, opts ...Option) *Bulkhead

New creates a Bulkhead with the given options.

func (*Bulkhead) Do

func (b *Bulkhead) Do(ctx context.Context, fn func() error) error

Do acquires a slot, waiting up to the configured timeout, then executes fn. Returns ErrBulkheadFull if the queue is at capacity. Returns ErrBulkheadTimeout if a slot is not acquired within the timeout. Returns ctx.Err() if the context is cancelled while waiting.

type Option

type Option func(*config)

Option configures a Bulkhead instance.

func WithMaxConcurrent

func WithMaxConcurrent(n int) Option

WithMaxConcurrent sets the maximum number of concurrent slots.

func WithMaxQueue

func WithMaxQueue(n int) Option

WithMaxQueue sets the maximum number of requests that can wait for a slot.

func WithOnDrop

func WithOnDrop(fn func(name string, reason string)) Option

WithOnDrop sets a callback invoked when a request is dropped.

func WithOnEnter

func WithOnEnter(fn func(name string, waitDuration time.Duration)) Option

WithOnEnter sets a callback invoked when a request acquires a slot.

func WithOnLeave

func WithOnLeave(fn func(name string)) Option

WithOnLeave sets a callback invoked when a request releases a slot.

func WithOnQueueEnter

func WithOnQueueEnter(fn func(name string)) Option

WithOnQueueEnter sets a callback invoked when a request enters the wait queue.

func WithOnQueueLeave

func WithOnQueueLeave(fn func(name string)) Option

WithOnQueueLeave sets a callback invoked when a request leaves the wait queue.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the maximum time a request will wait for a slot.

Jump to

Keyboard shortcuts

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