Don't use "select" with a single case that reads from a channel but read channel directly.

This commit is contained in:
Joachim Bauch 2020-07-31 15:32:42 +02:00
parent 7d874ac1a7
commit 68477474f8
Failed to extract signature
2 changed files with 7 additions and 11 deletions

View file

@ -288,8 +288,6 @@ func main() {
} }
} }
select { <-interrupt
case <-interrupt: log.Println("Interrupted")
log.Println("Interrupted")
}
} }

View file

@ -148,13 +148,11 @@ func (c *LoopbackNatsClient) Request(subject string, data []byte, timeout time.D
c.mu.Unlock() c.mu.Unlock()
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
select { <-ctx.Done()
case <-ctx.Done(): if ctx.Err() == context.DeadlineExceeded {
if ctx.Err() == context.DeadlineExceeded { err = nats.ErrTimeout
err = nats.ErrTimeout } else {
} else { err = ctx.Err()
err = ctx.Err()
}
} }
c.mu.Lock() c.mu.Lock()
return nil, err return nil, err