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 (*Hub) Len ¶
Len returns the total number of active subscribers across all requests. Intended for metrics and debugging.
func (*Hub) Publish ¶
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.