NewSubConn intercepts SubConn creation from pick_first children to wrap the StateListener for OOB listener management on READY transitions.
(addrs []resolver.Address, opts balancer.NewSubConnOptions)
| 113 | // NewSubConn intercepts SubConn creation from pick_first children to wrap the |
| 114 | // StateListener for OOB listener management on READY transitions. |
| 115 | func (b *orcab) NewSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) { |
| 116 | // The variable sc is declared before the closure so the closure captures |
| 117 | // the variable, not its (zero) value. After ClientConn.NewSubConn assigns |
| 118 | // to sc, the closure sees the real SubConn when invoked. |
| 119 | var sc balancer.SubConn |
| 120 | oldListener := opts.StateListener |
| 121 | opts.StateListener = func(state balancer.SubConnState) { |
| 122 | b.updateSubConnState(sc, state) |
| 123 | if oldListener != nil { |
| 124 | oldListener(state) |
| 125 | } |
| 126 | } |
| 127 | sc, err := b.ClientConn.NewSubConn(addrs, opts) |
| 128 | if err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | return sc, nil |
| 132 | } |
| 133 | |
| 134 | func (b *orcab) updateSubConnState(sc balancer.SubConn, state balancer.SubConnState) { |
| 135 | b.mu.Lock() |
nothing calls this directly
no test coverage detected