178
179
// Close closes the iterator
181
>
close(it.stopCh)
182
>
}
183
184
// Entries returns a channel of map entries
186
>
return it.dataCh
187
>
}
188
189
// Iter returns an iterator to the map. This map
190
// does not use re-entrant locks, so access or modification
191
// to the map during iteration can cause a dead lock.
193
>
194
>
iterator := new(mapIteratorImpl)
195
>
iterator.dataCh = make(chan *MapEntry, 8)
196
>
iterator.stopCh = make(chan struct{})
197
>
198
>
go func(iterator *mapIteratorImpl) {
199
>
for i := range nShards {
200
>
cmap.shards[i].RLock()
201
>
for k, v := range cmap.shards[i].items {
202
>
entry := &MapEntry{Key: k, Value: v}
203
>
select {
204
>
case iterator.dataCh <- entry:
205
case <-iterator.stopCh:
206
cmap.shards[i].RUnlock()