Returns a array of channels that contains elements in each shard, which likely takes a snapshot of `slm`. It returns once the size of each buffered channel is determined, before all the channels are populated using goroutines.
(slm ShardLockMaps)
| 332 | // It returns once the size of each buffered channel is determined, |
| 333 | // before all the channels are populated using goroutines. |
| 334 | func snapshot(slm ShardLockMaps) (chanList []chan Tuple) { |
| 335 | chanList = make([]chan Tuple, slm.shardCount) |
| 336 | wg := sync.WaitGroup{} |
| 337 | wg.Add(slm.shardCount) |
| 338 | for index, shard := range slm.shards { |
| 339 | go func(index int, shard *SingleShardMap) { |
| 340 | shard.RLock() |
| 341 | chanList[index] = make(chan Tuple, len(shard.items)) |
| 342 | wg.Done() |
| 343 | for key, val := range shard.items { |
| 344 | chanList[index] <- Tuple{key, val} |
| 345 | } |
| 346 | shard.RUnlock() |
| 347 | close(chanList[index]) |
| 348 | }(index, shard) |
| 349 | } |
| 350 | wg.Wait() |
| 351 | return chanList |
| 352 | } |
| 353 | |
| 354 | // fanIn reads elements from channels `chanList` into channel `out` |
| 355 | func fanIn(chanList []chan Tuple, out chan Tuple) { |