msghub

package
v3.1.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 5 Imported by: 0

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(historyLen int, extHost *extension.Host) *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) Delete

func (hub *Hub) Delete(mailbox string, id string)

Delete removes the message from the history buffer and instructs listeners to do the same.

func (*Hub) Dispatch

func (hub *Hub) Dispatch(msg event.MessageMetadata)

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) Start

func (hub *Hub) Start(ctx context.Context)

Start Hub processing loop.

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 event.MessageMetadata) error
	Delete(mailbox string, id string) error
}

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

Jump to

Keyboard shortcuts

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