Files
creator-hub/internal/controlplane/api/creator_updates.go
T
rogee c567080248 refactor(api): 删除运营链路与 runtime_use_lease
删除任务链(drafts/confirmations/tasks/attempts)、creator 运营链(策略/事件/操作/会话/消息/监听器/素材/关系)、runtime_use_lease 机制及其 API/UI;taskstate 包与对应测试一并移除。
2026-09-28 17:14:00 +08:00

40 lines
789 B
Go

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:
}
}
}