Skip to content

Commit

Permalink
Actually close the iterator channels.
Browse files Browse the repository at this point in the history
Change-Id: I6f6a2aef5ff55c6b2d21ad91d02ae6b0ecba4ae8
  • Loading branch information
Bjoern Rabenstein committed Nov 25, 2014
1 parent 8fba330 commit 7ad55ef
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions storage/local/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ func (sm seriesMap) del(fp clientmodel.Fingerprint) {
// iter returns a channel that produces all mappings in the seriesMap. The
// channel will be closed once all fingerprints have been received. Not
// consuming all fingerprints from the channel will leak a goroutine. The
// semantics of concurrent modification of seriesMap is the same as for
// iterating over a map with a 'range' clause.
// semantics of concurrent modification of seriesMap is the similar as the one
// for iterating over a map with a 'range' clause. However, if the next element
// in iteration order is removed after the current element has been received
// from the channel, it will still be produced by the channel.
func (sm seriesMap) iter() <-chan fingerprintSeriesPair {
ch := make(chan fingerprintSeriesPair)
go func() {
Expand All @@ -91,15 +93,18 @@ func (sm seriesMap) iter() <-chan fingerprintSeriesPair {
sm.mtx.RLock()
}
sm.mtx.RUnlock()
close(ch)
}()
return ch
}

// fpIter returns a channel that produces all fingerprints in the seriesMap. The
// channel will be closed once all fingerprints have been received. Not
// consuming all fingerprints from the channel will leak a goroutine. The
// semantics of concurrent modification of seriesMap is the same as for
// iterating over a map with a 'range' clause.
// semantics of concurrent modification of seriesMap is the similar as the one
// for iterating over a map with a 'range' clause. However, if the next element
// in iteration order is removed after the current element has been received
// from the channel, it will still be produced by the channel.
func (sm seriesMap) fpIter() <-chan clientmodel.Fingerprint {
ch := make(chan clientmodel.Fingerprint)
go func() {
Expand All @@ -110,6 +115,7 @@ func (sm seriesMap) fpIter() <-chan clientmodel.Fingerprint {
sm.mtx.RLock()
}
sm.mtx.RUnlock()
close(ch)
}()
return ch
}
Expand Down

0 comments on commit 7ad55ef

Please sign in to comment.