Skip to content

Commit

Permalink
Add code comments to new exports
Browse files Browse the repository at this point in the history
  • Loading branch information
umpc committed Jul 4, 2017
1 parent c43e372 commit 7046817
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import (
"time"
)

// IterChCloser allows records to be read through a channel that is returned by the Records method.
// IterChCloser values should be closed after use using the Close method.
type IterChCloser struct {
ch chan Record
canceled chan struct{}
}

// Close cancels a channel-based iteration and causes the sending goroutine to exit.
// Close should be used after an IterChCloser is finished being read from.
func (iterCh *IterChCloser) Close() error {
select {
case iterCh.canceled <- struct{}{}:
Expand All @@ -19,6 +23,8 @@ func (iterCh *IterChCloser) Close() error {
return nil
}

// Records returns nil if the IterChCloser has been closed.
// Otherwise, Record returns a channel that records can be read from.
func (iterCh *IterChCloser) Records() <-chan Record {
select {
case <-iterCh.canceled:
Expand Down

0 comments on commit 7046817

Please sign in to comment.