MCPcopy
hub / github.com/nats-io/nats.go / shufflePool

Method shufflePool

nats.go:2138–2148  ·  view source on GitHub ↗

shufflePool swaps randomly elements in the server pool The `offset` value indicates that the shuffling should start at this offset and leave the elements from [0..offset) intact.

(offset int)

Source from the content-addressed store, hash-verified

2136// The `offset` value indicates that the shuffling should start at
2137// this offset and leave the elements from [0..offset) intact.
2138func (nc *Conn) shufflePool(offset int) {
2139 if len(nc.srvPool) <= offset+1 {
2140 return
2141 }
2142 source := rand.NewSource(time.Now().UnixNano())
2143 r := rand.New(source)
2144 for i := offset; i < len(nc.srvPool); i++ {
2145 j := offset + r.Intn(i+1-offset)
2146 nc.srvPool[i], nc.srvPool[j] = nc.srvPool[j], nc.srvPool[i]
2147 }
2148}
2149
2150func (nc *Conn) newReaderWriter() {
2151 nc.br = &natsReader{

Callers 2

setupServerPoolMethod · 0.95
processInfoMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected