forked from TrueCloudLab/neoneo-go
stateroot: make it shutdown properly, not locking up whole system
This commit is contained in:
parent
863b9550e6
commit
4d0cbebb5a
1 changed files with 11 additions and 1 deletions
|
@ -17,6 +17,7 @@ func (s *service) Run() {
|
|||
}
|
||||
|
||||
func (s *service) run() {
|
||||
runloop:
|
||||
for {
|
||||
select {
|
||||
case b := <-s.blockCh:
|
||||
|
@ -27,13 +28,22 @@ func (s *service) run() {
|
|||
s.log.Error("can't sign or send state root", zap.Error(err))
|
||||
}
|
||||
case <-s.done:
|
||||
return
|
||||
break runloop
|
||||
}
|
||||
}
|
||||
drainloop:
|
||||
for {
|
||||
select {
|
||||
case <-s.blockCh:
|
||||
default:
|
||||
break drainloop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown stops the service.
|
||||
func (s *service) Shutdown() {
|
||||
s.chain.UnsubscribeFromBlocks(s.blockCh)
|
||||
close(s.done)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue