Skip to content

Commit

Permalink
reader: close channel on async read failure
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullin committed Mar 20, 2018
1 parent 00fd9fc commit b7cf4e1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions reader_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func (reader *Reader) ScanAsync(buffer int) chan *Rec {
vals := make(chan *Rec, buffer)

go func() {
// make sure we terminate the channel on scan read
defer close(vals)

err := reader.Scan(func(ri *ReaderInfo, data []byte) error {
vals <- &Rec{data, ri.ChunkPos, ri.StartPos, ri.NextPos}
return nil
Expand All @@ -24,8 +27,6 @@ func (reader *Reader) ScanAsync(buffer int) chan *Rec {
if err != nil {
log.Panic(err)
}

close(vals)
}()

return vals
Expand Down

0 comments on commit b7cf4e1

Please sign in to comment.