Package list golang-github-go-kit-kit / 9ef9fa0
Add comments Yuri Shkuro 4 years ago
1 changed file(s) with 5 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
117117 // Endpoints yields the current set of (presumably identical) endpoints, ordered
118118 // lexicographically by the corresponding instance string.
119119 func (c *endpointCache) Endpoints() ([]endpoint.Endpoint, error) {
120 // in the steady state we're going to have many goroutines calling Endpoints()
121 // concurrently, so to minimize contention we use a shared R-lock.
120122 c.mtx.RLock()
121123
122124 if c.err == nil || c.timeNow().Before(c.invalidateDeadline) {
125127 }
126128
127129 c.mtx.RUnlock()
130
131 // in case of an error, switch to an exclusive lock.
128132 c.mtx.Lock()
129133 defer c.mtx.Unlock()
130134
131 // Re-check due to a race between RUnlock() and Lock().
135 // re-check condition due to a race between RUnlock() and Lock().
132136 if c.err == nil || c.timeNow().Before(c.invalidateDeadline) {
133137 return c.endpoints, nil
134138 }