forked from TrueCloudLab/neoneo-go
oracle: wait for the service to stop during Shutdown
This commit is contained in:
parent
cab633ffed
commit
73e34514a5
1 changed files with 16 additions and 2 deletions
|
@ -53,6 +53,7 @@ type (
|
||||||
oracleSignContract []byte
|
oracleSignContract []byte
|
||||||
|
|
||||||
close chan struct{}
|
close chan struct{}
|
||||||
|
done chan struct{}
|
||||||
requestCh chan request
|
requestCh chan request
|
||||||
requestMap chan map[uint64]*state.OracleRequest
|
requestMap chan map[uint64]*state.OracleRequest
|
||||||
|
|
||||||
|
@ -123,6 +124,7 @@ func NewOracle(cfg Config) (*Oracle, error) {
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
|
|
||||||
close: make(chan struct{}),
|
close: make(chan struct{}),
|
||||||
|
done: make(chan struct{}),
|
||||||
requestMap: make(chan map[uint64]*state.OracleRequest, 1),
|
requestMap: make(chan map[uint64]*state.OracleRequest, 1),
|
||||||
pending: make(map[uint64]*state.OracleRequest),
|
pending: make(map[uint64]*state.OracleRequest),
|
||||||
responses: make(map[uint64]*incompleteTx),
|
responses: make(map[uint64]*incompleteTx),
|
||||||
|
@ -189,6 +191,7 @@ func (o *Oracle) Shutdown() {
|
||||||
o.running = false
|
o.running = false
|
||||||
close(o.close)
|
close(o.close)
|
||||||
o.getBroadcaster().Shutdown()
|
o.getBroadcaster().Shutdown()
|
||||||
|
<-o.done
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start runs the oracle service in a separate goroutine.
|
// Start runs the oracle service in a separate goroutine.
|
||||||
|
@ -213,11 +216,11 @@ func (o *Oracle) start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
tick := time.NewTicker(o.MainCfg.RefreshInterval)
|
tick := time.NewTicker(o.MainCfg.RefreshInterval)
|
||||||
|
main:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-o.close:
|
case <-o.close:
|
||||||
tick.Stop()
|
break main
|
||||||
return
|
|
||||||
case <-tick.C:
|
case <-tick.C:
|
||||||
var reprocess []uint64
|
var reprocess []uint64
|
||||||
o.respMtx.Lock()
|
o.respMtx.Lock()
|
||||||
|
@ -249,6 +252,17 @@ func (o *Oracle) start() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tick.Stop()
|
||||||
|
drain:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-o.requestMap:
|
||||||
|
default:
|
||||||
|
break drain
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(o.requestMap)
|
||||||
|
close(o.done)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateNativeContract updates native oracle contract info for tx verification.
|
// UpdateNativeContract updates native oracle contract info for tx verification.
|
||||||
|
|
Loading…
Reference in a new issue