broker

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message interface {
	WriteSSE(w io.Writer) error
}

type MessageBroker

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

func NewBroker

func NewBroker(done <-chan struct{}) *MessageBroker

NewBroker constructs new MessageBroker (zero value is not usable).

When "done" chan is closed all in-flight event streams (StreamSSE calls) will be terminated.

func (*MessageBroker) Broadcast

func (b *MessageBroker) Broadcast(msg Message)

func (*MessageBroker) Notify

func (b *MessageBroker) Notify(bearerPredicate []byte, msg Message)

func (*MessageBroker) StreamSSE

func (b *MessageBroker) StreamSSE(ctx context.Context, owner PubKey, w http.ResponseWriter) error

StreamSSE subscribes to broker with "owner" key and streams the messages it receives as server-sent events to "w" until "ctx" is cancelled or the "done" chan used as MessageBroker constructor parameter is closed (in both cases nil error is returned). Upon return it also unsubscribes from the message broker.

func (*MessageBroker) Subscribe

func (b *MessageBroker) Subscribe(pubkey PubKey) (<-chan Message, error)

func (*MessageBroker) Unsubscribe

func (b *MessageBroker) Unsubscribe(pubkey PubKey, c <-chan Message)

type PubKey

type PubKey []byte

Jump to

Keyboard shortcuts

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