Optimize channel handling

This commit is contained in:
Hendrik Hofstadt 2020-01-29 22:26:55 +01:00
parent 0ddfa34136
commit 40c218eb92
1 changed files with 6 additions and 2 deletions

View File

@ -211,7 +211,7 @@ func (m *Monitor) pollRoutine() {
for { for {
zap.L().Info("Starting poll routine") zap.L().Info("Starting poll routine")
func() { func() {
reqChan := make(chan *abi.OracleOracleRequest) reqChan := make(chan *abi.OracleOracleRequest, 100)
sub, err := m.oracle.WatchOracleRequest(nil, reqChan, nil) sub, err := m.oracle.WatchOracleRequest(nil, reqChan, nil)
if err != nil { if err != nil {
zap.L().Error("failed to watch oracle requests", zap.Error(err)) zap.L().Error("failed to watch oracle requests", zap.Error(err))
@ -219,7 +219,7 @@ func (m *Monitor) pollRoutine() {
} }
defer sub.Unsubscribe() defer sub.Unsubscribe()
headChan := make(chan *types.Header) headChan := make(chan *types.Header, 100)
sub2, err := m.client.SubscribeNewHead(context.Background(), headChan) sub2, err := m.client.SubscribeNewHead(context.Background(), headChan)
if err != nil { if err != nil {
zap.L().Error("failed to subscribe to new heads", zap.Error(err)) zap.L().Error("failed to subscribe to new heads", zap.Error(err))
@ -237,6 +237,8 @@ func (m *Monitor) pollRoutine() {
return return
case req, has := <-reqChan: case req, has := <-reqChan:
if !has { if !has {
zap.L().Error("request subscription closed", zap.Error(err))
return
} }
err := m.handleRequest(req) err := m.handleRequest(req)
if err != nil { if err != nil {
@ -245,6 +247,8 @@ func (m *Monitor) pollRoutine() {
} }
case header, has := <-headChan: case header, has := <-headChan:
if !has { if !has {
zap.L().Error("head subscription closed", zap.Error(err))
return
} }
// Update balances // Update balances