Source File
picker_wrapper.go
Belonging Package
google.golang.org/grpc
package grpc
import (
)
type pickerWrapper struct {
mu sync.Mutex
done bool
blockingCh chan struct{}
picker balancer.Picker
}
func () *pickerWrapper {
return &pickerWrapper{blockingCh: make(chan struct{})}
}
close(.blockingCh)
.blockingCh = make(chan struct{})
.mu.Unlock()
}
func ( *acBalancerWrapper, func(balancer.DoneInfo)) func(balancer.DoneInfo) {
.mu.Lock()
:= .ac
.mu.Unlock()
.incrCallsStarted()
return func( balancer.DoneInfo) {
if .Err != nil && .Err != io.EOF {
.incrCallsFailed()
} else {
.incrCallsSucceeded()
}
if != nil {
()
}
}
}
.mu.Unlock()
select {
case <-.Done():
var string
if != nil {
= "latest balancer error: " + .Error()
} else {
= .Err().Error()
}
switch .Err() {
case context.DeadlineExceeded:
return nil, nil, status.Error(codes.DeadlineExceeded, )
case context.Canceled:
return nil, nil, status.Error(codes.Canceled, )
}
case <-:
}
continue
}
= .blockingCh
:= .picker
.mu.Unlock()
, := .Pick()
if != nil {
if == balancer.ErrNoSubConnAvailable {
continue
}
if ! {
=
continue
}
return nil, nil, status.Error(codes.Unavailable, .Error())
}
, := .SubConn.(*acBalancerWrapper)
if ! {
logger.Error("subconn returned from pick is not *acBalancerWrapper")
continue
}
if , := .getAddrConn().getReadyTransport(); {
if channelz.IsOn() {
return , doneChannelzWrapper(, .Done), nil
}
return , .Done, nil
}
}
}
func ( *pickerWrapper) () {
.mu.Lock()
defer .mu.Unlock()
if .done {
return
}
.done = true
close(.blockingCh)
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |