breaker

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 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 ErrNotOperational = errors.New("breaker is not operational")

ErrNotOperational tells that Breaker has been shut 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(value 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() (deadline time.Time, ok bool)

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

func (*Breaker) Dec

func (b *Breaker) Dec()

Dec decrements number of 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 returns error which can be used in a manner similar to context.Context.Done().

func (*Breaker) Inc

func (b *Breaker) Inc() error

Inc increments number of tasks.

func (*Breaker) IsOperational added in v0.0.2

func (b *Breaker) IsOperational() bool

IsOperational checks whether breaker is in operational mode.

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(key interface{}) interface{}

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

func (*Breaker) Wait

func (b *Breaker) Wait()

Wait blocks until the number of tasks becomes equal to zero.

Jump to

Keyboard shortcuts

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