bus

package
v0.0.0-...-3c02646 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBusIsClosed is returned when the Bus has been closed and a Publish is attempted.
	ErrBusIsClosed = errors.New("bus has closed")
)
View Source
var (
	// ErrListenerIsClosed is returned when a listener is closed and a Send is attempted
	ErrListenerIsClosed = errors.New("listener is closed")
)

Functions

This section is empty.

Types

type Bus

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

Bus is an event bus responsible for sending/receiving events.

func New

func New(logger log.Logger) *Bus

New creates a Bus returning its pointer.

func (*Bus) Close

func (b *Bus) Close()

Close closes all listener channels and empties the list of subscribed listeners.

func (*Bus) Listeners

func (b *Bus) Listeners(topic string) int

Listeners returns the number of listeners that are registered for a given topic.

func (*Bus) On

func (b *Bus) On(topic string, buffer int) (xid.ID, <-chan *pubsub.Message)

On subscribes to a specific topic with the given buffer size.

func (*Bus) Once

func (b *Bus) Once(topic string) (xid.ID, <-chan *pubsub.Message)

Once subscribes to a specific topic. The listener will be closed immediately after at least one message is received.

func (*Bus) Publish

func (b *Bus) Publish(topic string, msg *pubsub.Message) error

Publish publishes a msg to the given topic.

func (*Bus) Unsubscribe

func (b *Bus) Unsubscribe(topic string, id xid.ID)

Unsubscribe unsubscribes the listener by ID from the given topic.

type Listener

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

Listener tracks a single subscription.

func (*Listener) Close

func (l *Listener) Close()

Close closes the channel and prevents further message sending.

func (*Listener) Count

func (l *Listener) Count() int

Count returns the total count of messages receives through the Listener.

func (*Listener) HasReceivedMessages

func (l *Listener) HasReceivedMessages() bool

HasReceivedMessages returns true if the Listener has receives at least once message.

func (*Listener) Send

func (l *Listener) Send(msg *pubsub.Message) error

Send sends the provided msg through the listener's channel, incrementing the message count and

Jump to

Keyboard shortcuts

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