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 {
case <-interrupt:
log.Println("Interrupted")
}
<-interrupt
log.Println("Interrupted")
}

View file

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