Skip to content

Commit

Permalink
Refactor (*ReaderLease).Reader to (*ReaderLease).NewReader
Browse files Browse the repository at this point in the history
  • Loading branch information
hinshun committed Jun 26, 2018
1 parent 25784f7 commit f880c1c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 5 additions & 3 deletions reader_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ func NewReaderLease(reader io.Reader) *ReaderLease {
return rm
}

// Reader returns a cancellable io.Reader for the underlying io.Reader. New
// readers can be created after previous ones have been cancelled.
func (rm *ReaderLease) Reader(ctx context.Context) io.Reader {
// NewReader returns a cancellable io.Reader for the underlying io.Reader.
// Readers can be cancelled without interrupting other Readers, and once
// a reader is a cancelled it will not read anymore bytes from ReaderLease's
// underlying io.Reader.
func (rm *ReaderLease) NewReader(ctx context.Context) io.Reader {
return NewChanReader(ctx, rm.bytec)
}

Expand Down
3 changes: 1 addition & 2 deletions reader_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ func TestReaderLease(t *testing.T) {
for _, test := range tests {
t.Run(test.title, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
r := rm.Reader(ctx)
tin, tout := io.Pipe()

var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
io.Copy(tout, r)
io.Copy(tout, rm.NewReader(ctx))
}()

wg.Add(1)
Expand Down

0 comments on commit f880c1c

Please sign in to comment.