Files
kanban_cpp/backend/sse_hub.go
T
agent 255e8dcf71 feat: initial scaffold of kanban_cpp v2 (issue 0130)
Frontend C++ ImGui (main.cpp + 4 paneles) + backend Go (HTTP + SQLite + fsnotify + SSE).
Reusa parse/scan/watch funcs del registry (issue 0130a).
2026-05-22 22:19:47 +02:00

47 lines
731 B
Go

package main
import (
"sync"
)
type SSEEvent struct {
Type string `json:"type"`
ID string `json:"id"`
Path string `json:"path,omitempty"`
}
type SSEHub struct {
mu sync.RWMutex
clients map[chan SSEEvent]struct{}
}
func newSSEHub() *SSEHub {
return &SSEHub{clients: map[chan SSEEvent]struct{}{}}
}
func (h *SSEHub) subscribe() chan SSEEvent {
ch := make(chan SSEEvent, 16)
h.mu.Lock()
h.clients[ch] = struct{}{}
h.mu.Unlock()
return ch
}
func (h *SSEHub) unsubscribe(ch chan SSEEvent) {
h.mu.Lock()
delete(h.clients, ch)
h.mu.Unlock()
close(ch)
}
func (h *SSEHub) broadcast(ev SSEEvent) {
h.mu.RLock()
defer h.mu.RUnlock()
for ch := range h.clients {
select {
case ch <- ev:
default:
}
}
}