1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-06-19 01:09:55 -04:00

dont start periodic task until necessary

This commit is contained in:
Darien Raymond
2018-08-29 23:00:01 +02:00
parent 5a0a9aa65e
commit eb05a92592
10 changed files with 81 additions and 162 deletions

View File

@@ -1,6 +1,7 @@
package pubsub
import (
"errors"
"sync"
"time"
@@ -47,7 +48,6 @@ func NewService() *Service {
Execute: s.Cleanup,
Interval: time.Second * 30,
}
common.Must(s.ctask.Start())
return s
}
@@ -57,6 +57,10 @@ func (s *Service) Cleanup() error {
s.Lock()
defer s.Unlock()
if len(s.subs) == 0 {
return errors.New("nothing to do")
}
for name, subs := range s.subs {
newSub := make([]*Subscriber, 0, len(s.subs))
for _, sub := range subs {
@@ -86,6 +90,7 @@ func (s *Service) Subscribe(name string) *Subscriber {
subs := append(s.subs[name], sub)
s.subs[name] = subs
s.Unlock()
common.Must(s.ctask.Start())
return sub
}