breaker

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package breaker contains useful thread-safe abstraction the helps to control lifetime of actors, background tasks, pools etc.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrShutdown indicates that the breaker has already shut down.
	ErrShutdown = errors.New("breaker is shut down")

	// ErrShuttingDown indicates that shutdown has started
	// and the breaker no longer accepts new tasks.
	ErrShuttingDown = errors.New("breaker is shutting down")
)

Functions

This section is empty.

Types

type Breaker

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

Breaker can be used to stop any subsystem with background tasks gracefully.

func NewBreaker

func NewBreaker() *Breaker

NewBreaker - default breaker constructor.

func NewBreakerWithInitValue

func NewBreakerWithInitValue(count int64) *Breaker

NewBreakerWithInitValue - alternative breaker constructor convenient for usage in pools and actors, when you know how many goroutines will work from the very beginning.

func (*Breaker) Deadline

func (b *Breaker) Deadline() (time.Time, bool)

Deadline is implemented for the sake of compatibility with context.Context.

func (Breaker) Dec

func (b Breaker) Dec()

Dec decrements the number of active tasks.

func (*Breaker) Done

func (b *Breaker) Done() <-chan struct{}

Done returns channel which can be used in a manner similar to context.Context.Done().

func (Breaker) Err

func (b Breaker) Err() error

Err mirrors context.Context semantics: nil while operational, otherwise ErrShutdown.

func (Breaker) Inc

func (b Breaker) Inc() error

Inc increments the number of active tasks.

func (Breaker) IsOperational added in v0.0.2

func (b Breaker) IsOperational() bool

IsOperational reports whether the breaker is still accepting new tasks.

func (*Breaker) Shutdown

func (b *Breaker) Shutdown()

Shutdown switches breaker in shutdown mode.

func (*Breaker) ShutdownAndWait

func (b *Breaker) ShutdownAndWait()

ShutdownAndWait switches breakers in shutdown mode and waits for all background tasks to terminate.

func (*Breaker) Value

func (b *Breaker) Value(_ any) any

Value is implemented for the sake of compatibility with context.Context.

func (Breaker) Wait

func (b Breaker) Wait()

Wait blocks until the number of active tasks reaches zero.

Jump to

Keyboard shortcuts

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