Skip to content

Commit

Permalink
Merge pull request #31 from whyrusleeping/master
Browse files Browse the repository at this point in the history
use a timer instead of 'After' to avoid leaking resources
  • Loading branch information
armon authored Jul 20, 2016
2 parents badf81f + b36b43f commit d2be601
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,17 @@ START:

WAIT:
var timeout <-chan time.Time
var timer *time.Timer
if !s.readDeadline.IsZero() {
delay := s.readDeadline.Sub(time.Now())
timeout = time.After(delay)
timer = time.NewTimer(delay)
timeout = timer.C
}
select {
case <-s.recvNotifyCh:
if timer != nil {
timer.Stop()
}
goto START
case <-timeout:
return 0, ErrTimeout
Expand Down

0 comments on commit d2be601

Please sign in to comment.