sse

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sse provides Server-Sent Events broadcasting for engram.

Index

Constants

View Source
const (
	// WriteTimeout is the timeout for writing to SSE clients.
	// Prevents blocking on stale connections.
	WriteTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

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

Broadcaster manages SSE client connections and message broadcasting.

func NewBroadcaster

func NewBroadcaster() *Broadcaster

NewBroadcaster creates a new SSE broadcaster.

func (*Broadcaster) AddClient

func (b *Broadcaster) AddClient(w http.ResponseWriter) (*Client, error)

AddClient adds a new SSE client connection.

func (*Broadcaster) Broadcast

func (b *Broadcaster) Broadcast(data interface{})

Broadcast sends a message to all connected clients. Uses non-blocking writes with timeout to prevent stale connections from blocking.

func (*Broadcaster) ClientCount

func (b *Broadcaster) ClientCount() int

ClientCount returns the number of connected clients.

func (*Broadcaster) HandleSSE

func (b *Broadcaster) HandleSSE(w http.ResponseWriter, r *http.Request)

HandleSSE handles an SSE connection request.

func (*Broadcaster) RemoveClient

func (b *Broadcaster) RemoveClient(client *Client)

RemoveClient removes a client connection.

type Client

type Client struct {
	Writer  http.ResponseWriter
	Flusher http.Flusher
	Done    chan struct{}
	ID      string
}

Client represents a connected SSE client.

Jump to

Keyboard shortcuts

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