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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user