package api import ( "sync" ) // creatorUpdateHub 向 SSE 订阅者广播运营数据变更通知。 type creatorUpdateHub struct { mu sync.Mutex subscribers map[chan struct{}]struct{} } var creatorUpdates = &creatorUpdateHub{subscribers: make(map[chan struct{}]struct{})} func (h *creatorUpdateHub) subscribe() (<-chan struct{}, func()) { channel := make(chan struct{}, 1) h.mu.Lock() h.subscribers[channel] = struct{}{} h.mu.Unlock() return channel, func() { h.mu.Lock() if _, ok := h.subscribers[channel]; ok { delete(h.subscribers, channel) close(channel) } h.mu.Unlock() } } func (h *creatorUpdateHub) publish() { h.mu.Lock() defer h.mu.Unlock() for channel := range h.subscribers { select { case channel <- struct{}{}: default: } } }