This commit is contained in:
2026-08-16 20:58:57 +08:00
parent a85477be80
commit a9e1f9e6f8
42 changed files with 1569 additions and 156 deletions
+13
View File
@@ -67,6 +67,7 @@ func (s *TaskScheduler) Start(ctx context.Context) error {
}
func (s *TaskScheduler) Stop(ctx context.Context) error {
s.closeSubscribers()
s.ctxMu.Lock()
if s.cancel != nil {
s.cancel()
@@ -241,6 +242,18 @@ func (s *TaskScheduler) Unsubscribe(userID uint, ch chan []byte) {
}
s.subMu.Unlock()
}
func (s *TaskScheduler) closeSubscribers() {
s.subMu.Lock()
defer s.subMu.Unlock()
for userID, subscribers := range s.subscribers {
for ch := range subscribers {
close(ch)
}
delete(s.subscribers, userID)
}
}
func (s *TaskScheduler) PublishToUsers(userIDs []uint, value any) {
raw, err := json.Marshal(value)
if err != nil {