NewBalancer is the constructor for the lazy balancer.
(cc balancer.ClientConn, bOpts balancer.BuildOptions, childBuilder ChildBuilderFunc)
| 51 | |
| 52 | // NewBalancer is the constructor for the lazy balancer. |
| 53 | func NewBalancer(cc balancer.ClientConn, bOpts balancer.BuildOptions, childBuilder ChildBuilderFunc) balancer.Balancer { |
| 54 | b := &lazyBalancer{ |
| 55 | cc: cc, |
| 56 | buildOptions: bOpts, |
| 57 | childBuilder: childBuilder, |
| 58 | } |
| 59 | b.logger = internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(logPrefix, b)) |
| 60 | cc.UpdateState(balancer.State{ |
| 61 | ConnectivityState: connectivity.Idle, |
| 62 | Picker: &idlePicker{exitIdle: sync.OnceFunc(func() { |
| 63 | // Call ExitIdle in a new goroutine to avoid deadlocks while calling |
| 64 | // back into the channel synchronously. |
| 65 | go b.ExitIdle() |
| 66 | })}, |
| 67 | }) |
| 68 | return b |
| 69 | } |
| 70 | |
| 71 | type lazyBalancer struct { |
| 72 | // The following fields are initialized at build time and read-only after |