concurrent

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: AGPL-3.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSigInactive   = errors.New("signaller inactive")
	ErrSigNoListener = errors.New("no signal listener")
)

Error codes

Functions

This section is empty.

Types

type Listener added in v1.2.13

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

Listener for signals managed by Signaller

func (*Listener) Signal added in v1.2.13

func (l *Listener) Signal() <-chan Signal

Signal returns the channel from which to read the signal.

type Signal

type Signal interface{}

Signal can be any object (intrinsic or custom); it is the responsibility of the senders and receivers of signals to handle them accordingly.

type Signaller

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

Signaller dispatches signals to multiple concurrent listeners. The sequence in which listeners are served is stochastic.

In highly concurrent environments with a lot of messages the sequence of signals seen by a listener can vary. This is due to the fact that a signal gets dispatched in a Go routine, so the next signal can be dispatched before a listener got the first one if the second Go routine handles the listener earlier. It is therefore mandatory that received signals from a listener get handled in a Go routine as well to keep latency low. If a listener violates that promise, it got removed from the list.

func NewSignaller

func NewSignaller() *Signaller

NewSignaller instantiates a new signal manager:

func (*Signaller) Drop

func (s *Signaller) Drop(listener *Listener) error

Drop removes a listener from the list. Failing to drop or close a listener will result in hanging go routines.

func (*Signaller) Listener added in v1.2.13

func (s *Signaller) Listener() (*Listener, error)

Listener returns a new channel to listen on each time it is called. Function interested in listening should get the channel, start the for/select loop and drop the channel if the loop terminates. Requesting an listener and than not reading from it will block all other listeners of the signaller.

func (*Signaller) Retire

func (s *Signaller) Retire()

Retire a signaller: This will terminate the dispatch loop for signals; no further send or listen operations are supported. A retired signaller cannot be re-activated.

func (*Signaller) Send

func (s *Signaller) Send(sig Signal) error

Send a signal to be dispatched to all listeners.

func (*Signaller) SetLatency added in v1.2.13

func (s *Signaller) SetLatency(d time.Duration)

SetLatency sets the max latency for listener. A listener is removed from the list if it violates this policy.

Jump to

Keyboard shortcuts

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