nodeconf: stop update loop on close
This commit is contained in:
parent
b7eb185463
commit
d819f7773e
@ -36,9 +36,12 @@ type service struct {
|
||||
store Store
|
||||
last NodeConf
|
||||
mu sync.RWMutex
|
||||
updateCtx context.Context
|
||||
updateCtxCancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (s *service) Init(a *app.App) (err error) {
|
||||
s.updateCtx, s.updateCtxCancel = context.WithCancel(context.Background())
|
||||
s.config = a.MustComponent("config").(ConfigGetter).GetNodeConf()
|
||||
s.accountId = a.MustComponent(commonaccount.CName).(commonaccount.Service).Account().PeerId
|
||||
s.source = a.MustComponent(CNameSource).(Source)
|
||||
@ -61,7 +64,14 @@ func (s *service) Run(_ context.Context) (err error) {
|
||||
}
|
||||
|
||||
func (s *service) updateLoop(ctx context.Context) {
|
||||
for _ = range time.NewTicker(time.Minute * 10).C {
|
||||
ticker := time.NewTicker(time.Minute * 10)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-s.updateCtx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
}
|
||||
err := s.updateConfiguration(ctx)
|
||||
if err != nil {
|
||||
if err == ErrConfigurationNotChanged {
|
||||
@ -201,5 +211,8 @@ func (s *service) NodeTypes(nodeId string) []NodeType {
|
||||
}
|
||||
|
||||
func (s *service) Close(ctx context.Context) (err error) {
|
||||
if s.updateCtxCancel != nil {
|
||||
s.updateCtxCancel()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user