Simplify by using a single buffered channel, instead of having a done

channel and a regular channel - thanks @aaronlehmann!

Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
Ying Li 2015-10-15 11:43:17 -07:00
parent 23a5d42bf6
commit faff328d62
1 changed files with 2 additions and 8 deletions

View File

@ -125,17 +125,13 @@ func (trust *NotarySigner) checkServiceHealth(
// We still want to time out getting health, because the connection could // We still want to time out getting health, because the connection could
// have disconnected sometime between when we checked the connection and // have disconnected sometime between when we checked the connection and
// when we try to make an RPC call. // when we try to make an RPC call.
channel := make(chan error) channel := make(chan error, 1)
done := make(chan struct{})
go func() { go func() {
status, err := check(context.Background(), &pb.Void{}) status, err := check(context.Background(), &pb.Void{})
if len(status.Status) > 0 { if len(status.Status) > 0 {
err = fmt.Errorf("%s not healthy", serviceName) err = fmt.Errorf("%s not healthy", serviceName)
} }
select { channel <- err
case <-done:
case channel <- err:
}
}() }()
var returnErr error var returnErr error
select { select {
@ -144,7 +140,5 @@ func (trust *NotarySigner) checkServiceHealth(
case <-time.After(time.Second * time.Duration(timeout)): case <-time.After(time.Second * time.Duration(timeout)):
returnErr = fmt.Errorf("Timed out connecting to %s after %s", serviceName, timeout) returnErr = fmt.Errorf("Timed out connecting to %s after %s", serviceName, timeout)
} }
close(done)
close(channel)
return returnErr return returnErr
} }