MCPcopy
hub / github.com/grpc/grpc-go / NewBalancer

Function NewBalancer

balancer/lazy/lazy.go:53–69  ·  view source on GitHub ↗

NewBalancer is the constructor for the lazy balancer.

(cc balancer.ClientConn, bOpts balancer.BuildOptions, childBuilder ChildBuilderFunc)

Source from the content-addressed store, hash-verified

51
52// NewBalancer is the constructor for the lazy balancer.
53func 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
71type lazyBalancer struct {
72 // The following fields are initialized at build time and read-only after

Callers 6

TestExitIdleMethod · 0.92
TestPickerMethod · 0.92
lazyPickFirstBuilderFunction · 0.92

Calls 2

ExitIdleMethod · 0.95
UpdateStateMethod · 0.65

Tested by 5

TestExitIdleMethod · 0.74
TestPickerMethod · 0.74