sse

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package sse provides an in-process pub/sub hub for server-sent event notifications, keyed by request UUID. It allows SSE HTTP handlers to subscribe for real-time notifications when a request's state changes.

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 is a lightweight, thread-safe pub/sub dispatcher keyed by request ID. Subscribers receive a signal whenever Publish is called for their request.

func NewHub

func NewHub() *Hub

NewHub creates a new event hub.

func (*Hub) Len

func (h *Hub) Len() int

Len returns the total number of active subscribers across all requests. Intended for metrics and debugging.

func (*Hub) Publish

func (h *Hub) Publish(requestID uuid.UUID)

Publish sends a non-blocking signal to all subscribers for the given request ID. Subscribers that already have a pending signal are skipped (the buffered channel coalesces rapid publishes). This is safe to call from any goroutine — it takes a read lock since it only reads the subscriber map and does non-blocking channel sends.

func (*Hub) Subscribe

func (h *Hub) Subscribe(requestID uuid.UUID) *Subscriber

Subscribe registers a new subscriber for the given request ID. The returned Subscriber's channel receives a signal each time Publish is called for that request. Call Unsubscribe to clean up.

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(requestID uuid.UUID, sub *Subscriber)

Unsubscribe removes a subscriber and cleans up the request key if no subscribers remain.

type Subscriber

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

Subscriber holds the notification channel for a single SSE connection.

func (*Subscriber) C

func (s *Subscriber) C() <-chan struct{}

C returns the channel that receives signals on state changes.

Jump to

Keyboard shortcuts

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