msghub

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 5, 2018 License: MIT Imports: 3 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

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

Hub relays messages on to its listeners

func New

func New(ctx context.Context, historyLen int) *Hub

New constructs a new Hub which will cache historyLen messages in memory for playback to future listeners. A goroutine is created to handle incoming messages; it will run until the provided context is canceled.

func (*Hub) AddListener

func (hub *Hub) AddListener(l Listener)

AddListener registers a listener to receive broadcasted messages.

func (*Hub) Dispatch

func (hub *Hub) Dispatch(msg Message)

Dispatch queues a message for broadcast by the hub. The message will be placed into the history buffer and then relayed to all registered listeners.

func (*Hub) RemoveListener

func (hub *Hub) RemoveListener(l Listener)

RemoveListener deletes a listener registration, it will cease to receive messages.

func (*Hub) Sync

func (hub *Hub) Sync()

Sync blocks until the msghub has processed its queue up to this point, useful for unit tests.

type Listener

type Listener interface {
	Receive(msg Message) error
}

Listener receives the contents of the history buffer, followed by new messages

type Message

type Message struct {
	Mailbox string
	ID      string
	From    string
	To      []string
	Subject string
	Date    time.Time
	Size    int64
}

Message contains the basic header data for a message

Jump to

Keyboard shortcuts

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