1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Hold the event source when there are no listeners (#15725)

* Hold the event source when there are no listeners

The event source does not need to run when there are no listeners. Therefore
pause it when there are none.

* add some more logging

Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
zeripath
2021-05-15 22:46:13 +01:00
committed by GitHub
parent f582ec4e53
commit 8e32eeb5de
2 changed files with 35 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ type Manager struct {
mutex sync.Mutex
messengers map[int64]*Messenger
connection chan struct{}
}
var manager *Manager
@@ -20,6 +21,7 @@ var manager *Manager
func init() {
manager = &Manager{
messengers: make(map[int64]*Messenger),
connection: make(chan struct{}, 1),
}
}
@@ -36,6 +38,10 @@ func (m *Manager) Register(uid int64) <-chan *Event {
messenger = NewMessenger(uid)
m.messengers[uid] = messenger
}
select {
case m.connection <- struct{}{}:
default:
}
m.mutex.Unlock()
return messenger.Register()
}