mirror of https://github.com/docker/docs.git
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:
parent
23a5d42bf6
commit
faff328d62
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue