Documentation
¶
Index ¶
- func HandleSSE(broker *Broker) forge.SSEHandler
- type Broker
- func (b *Broker) AddClient(stream forge.Stream) (string, <-chan struct{})
- func (b *Broker) Broadcast(event Event)
- func (b *Broker) BroadcastJSON(eventType EventType, data any)
- func (b *Broker) ClientCount() int
- func (b *Broker) Close()
- func (b *Broker) KeepAlive() time.Duration
- func (b *Broker) RemoveClient(id string)
- type Event
- type EventType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleSSE ¶
func HandleSSE(broker *Broker) forge.SSEHandler
HandleSSE returns a forge SSE handler that connects clients to the broker. The handler runs for the lifetime of the client connection, sending keep-alive comments at the configured interval. The broker broadcasts events to all connected clients. The handler exits when the client disconnects OR when the broker is closed (e.g. during application shutdown), whichever comes first.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker manages SSE client connections and broadcasts events.
func (*Broker) AddClient ¶
AddClient registers a new SSE stream as a client. Returns the client ID and a channel that is closed when the client is removed (either explicitly via RemoveClient or when the broker is closed). SSE handlers should select on the done channel to exit promptly on shutdown.
func (*Broker) Broadcast ¶
Broadcast sends an event to all connected clients concurrently. Failed sends cause the client to be removed.
func (*Broker) BroadcastJSON ¶
BroadcastJSON sends a JSON event to all connected clients.
func (*Broker) ClientCount ¶
ClientCount returns the number of connected clients.
func (*Broker) Close ¶
func (b *Broker) Close()
Close shuts down the broker and disconnects all clients.
func (*Broker) RemoveClient ¶
RemoveClient removes a client by ID.