Skip to content

Commit

Permalink
utils/chunker: fix blocking done chan. fixes #467
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Sep 17, 2018
1 parent fbc919b commit be04cd9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions utils/chunker/stream.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package chunker

import "io"
import (
"io"
"sync"
)

// Stream implements io.Reader.
type Stream struct {
recv chan []byte

done chan struct{}
m sync.Mutex

data []byte
i int64
Expand Down Expand Up @@ -49,10 +54,12 @@ func (s *Stream) Read(p []byte) (n int, err error) {

// Close closes reader.
func (s *Stream) Close() error {
s.m.Lock()
defer s.m.Unlock()
if s.done == nil {
return nil
}
close(s.done)
s.done <- struct{}{}
s.done = nil
return nil
}

0 comments on commit be04cd9

Please sign in to comment.