Add M0 server skeleton with SQLite store, SSE events, worktrees, and tailscale service

This commit is contained in:
Ian Gulliver
2026-10-13 22:19:20 -07:00
parent 555a55efc8
commit 2328904131
26 changed files with 3030 additions and 194 deletions
+53
View File
@@ -0,0 +1,53 @@
package server
import (
"sync"
"g.fc.run/misc/byre/internal/api"
)
type hub struct {
mu sync.Mutex
subs map[chan api.Event]bool
}
func newHub() *hub {
return &hub{subs: map[chan api.Event]bool{}}
}
func (h *hub) subscribe() chan api.Event {
h.mu.Lock()
defer h.mu.Unlock()
ch := make(chan api.Event, 256)
h.subs[ch] = true
return ch
}
func (h *hub) unsubscribe(ch chan api.Event) {
h.mu.Lock()
defer h.mu.Unlock()
if !h.subs[ch] {
return
}
delete(h.subs, ch)
close(ch)
}
func (h *hub) publish(ev api.Event) {
h.mu.Lock()
defer h.mu.Unlock()
for ch := range h.subs {
select {
case ch <- ev:
default:
delete(h.subs, ch)
close(ch)
}
}
}
func (h *hub) count() int {
h.mu.Lock()
defer h.mu.Unlock()
return len(h.subs)
}