eventsource

package
v1.21.11 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 16 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Name represents the value of the event: tag in the stream
	Name string
	// Data is either JSONified []byte or any that can be JSONd
	Data any
	// ID represents the ID of an event
	ID string
	// Retry tells the receiver only to attempt to reconnect to the source after this time
	Retry time.Duration
}

Event is an eventsource event, not all fields need to be set

func (*Event) String

func (e *Event) String() string

func (*Event) WriteTo

func (e *Event) WriteTo(w io.Writer) (int64, error)

WriteTo writes data to w until there's no more data to write or when an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

type Manager

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

Manager manages the eventsource Messengers

func GetManager

func GetManager() *Manager

GetManager returns a Manager and initializes one as singleton if there's none yet

func (*Manager) Init

func (m *Manager) Init()

Init starts this eventsource

func (*Manager) Register

func (m *Manager) Register(uid int64) <-chan *Event

Register message channel

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run runs the manager within a provided context

func (*Manager) SendMessage

func (m *Manager) SendMessage(uid int64, message *Event)

SendMessage sends a message to a particular user

func (*Manager) SendMessageBlocking

func (m *Manager) SendMessageBlocking(uid int64, message *Event)

SendMessageBlocking sends a message to a particular user

func (*Manager) Unregister

func (m *Manager) Unregister(uid int64, channel <-chan *Event)

Unregister message channel

func (*Manager) UnregisterAll

func (m *Manager) UnregisterAll()

UnregisterAll message channels

type Messenger

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

Messenger is a per uid message store

func NewMessenger

func NewMessenger(uid int64) *Messenger

NewMessenger creates a messenger for a particular uid

func (*Messenger) Register

func (m *Messenger) Register() <-chan *Event

Register returns a new chan []byte

func (*Messenger) SendMessage

func (m *Messenger) SendMessage(message *Event)

SendMessage sends the message to all registered channels

func (*Messenger) SendMessageBlocking

func (m *Messenger) SendMessageBlocking(message *Event)

SendMessageBlocking sends the message to all registered channels and ensures it gets sent

func (*Messenger) Unregister

func (m *Messenger) Unregister(channel <-chan *Event) bool

Unregister removes the provider chan []byte

func (*Messenger) UnregisterAll

func (m *Messenger) UnregisterAll()

UnregisterAll removes all chan []byte

Jump to

Keyboard shortcuts

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