bus

package
v0.0.0-...-caf0cee Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT, Unlicense Imports: 3 Imported by: 1

Documentation

Overview

Package bus provides a thread-safe message passing mechanism for applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus interface {
	// Connect establishes a connection.
	Connect() Connection
	// Close closes all connections, and cleans up all bus resources. It blocks
	// until all event processing from events sent prior to Close() completes.
	Close()
}

Bus defines a concurrent-safe, cross-application message passing mechanism. Asynchronous or decoupled logical units within the application can establish connections to the bus to send and receive messages.

func New

func New() Bus

New constructs a new bus.

func NewBuffered

func NewBuffered(buffering int) Bus

New constructs a new bus with configurable bus channel buffering. Higher buffering values use more memory but run more efficiently with high throughput.

type Connection

type Connection interface {
	// Output returns a channel on which bus events can be read.
	Output() <-chan any
	// Omnicast sends the provided value to all connections to the bus including
	// the connection used to send the value. Messages sent
	// while the connection is closed or closing will be discarded.
	Omnicast(any)
	// OmnicastSync is a synchronous Omnicast that returns whether the send was
	// successful.
	OmnicastSync(any) bool
	// Broadcast sends the provided value to all connections to the bus other than
	// the connection used to send the value. Messages sent
	// while the connection is closed or closing will be discarded.
	Broadcast(any)
	// BroadcastSync is a synchronous Broadcast that returns whether the send was
	// successful.
	BroadcastSync(any) bool
	// Loopback sends the provided value to the output channel of only the connection
	// it is called upon. Messages sent
	// while the connection is closed or closing will be discarded.
	Loopback(any)
	// LoopbackSync is a synchronous Loopback that returns whether the send was
	// successful.
	LoopbackSync(any) bool
	// Close initiates closing this connection. The connection is not fully closed until
	// the channel returned by Output closes. Proper use requires reading all remaining
	// events until the channel closes.
	Close()
}

Connection defines methods for sending and receiving data from a bus, as well as safely scheduing asynchronous work.

Jump to

Keyboard shortcuts

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