func()

in grpcgcp/multiendpoint/multiendpoint.go [179:207]


func (me *multiEndpoint) maybeUpdateCurrent() {
	c, exists := me.endpoints[me.current]
	var topA *endpoint
	var top *endpoint
	for _, e := range me.endpoints {
		if e.status == available && (topA == nil || topA.priority > e.priority) {
			topA = e
		}
		if top == nil || top.priority > e.priority {
			top = e
		}
	}

	if exists && c.status == recovering && (topA == nil || topA.priority > c.priority) {
		// Let current endpoint recover while no higher priority endpoints available.
		return
	}

	// Always prefer top available endpoint.
	if topA != nil {
		me.switchFromTo(c, topA)
		return
	}

	// If no current endpoint exists, resort to the top priority endpoint immediately.
	if !exists {
		me.current = top.id
	}
}