bus

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTopicEmpty    = errors.New("the topic is empty")
	ErrTopicNotExist = errors.New("the topic does not exist")
	ErrListenerEmpty = errors.New("the message listener is empty")
	ErrEmptyFuture   = errors.New("can't invoke Get() on an empty future")
)

Functions

This section is empty.

Types

type Bus

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

The Bus allows publish-subscribe-style communication between components

func NewBus

func NewBus() *Bus

func (*Bus) Publish

func (b *Bus) Publish(topic Topic, message ...Message) (Future, error)

func (*Bus) Subscribe

func (b *Bus) Subscribe(topic Topic, listener MessageListener) error

Subscribe adds an MessageListener to be called when a message of a Topic is posted.

type ChType

type ChType int
var (
	ChTypeUnidirectional ChType = 0
	ChTypeBidirectional  ChType = 1
)

type Channel

type Channel chan Event

type Event

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

type Future

type Future interface {
	Get() (Message, error)
	GetAll() ([]Message, error)
}

type Message

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

Message is send on the bus to all subscribed listeners

func NewMessage

func NewMessage(id MessageID, data interface{}) Message

func (Message) Data

func (m Message) Data() interface{}

func (Message) ID

func (m Message) ID() MessageID

type MessageID

type MessageID uint64

type MessageListener

type MessageListener interface {
	Rev(message Message) Message
}

MessageListener is the signature of functions that can handle an EventMessage.

type Payload

type Payload interface{}

Payload represents a simple data

type Publisher

type Publisher interface {
	Publish(topic Topic, message ...Message) (Future, error)
}

type Subscriber

type Subscriber interface {
	Subscribe(topic Topic, listener MessageListener) error
}

type Topic

type Topic struct {
	ID   string
	Type ChType
}

func BiTopic

func BiTopic(ID string) Topic

func UniTopic

func UniTopic(ID string) Topic

Jump to

Keyboard shortcuts

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