Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Make channels buffered to prevent goroutines leak. #5

Merged
merged 1 commit into from Jan 23, 2014
Merged

Make channels buffered to prevent goroutines leak. #5

merged 1 commit into from Jan 23, 2014

Conversation

bredov
Copy link
Contributor

@bredov bredov commented Jan 23, 2014

Users may ignore done message. Also, functions which runs two goroutines that writes to one channel will always produce a leak.
Killable must send kill message if user didn't.

Users may ignore done message. Also, functions which runs two goroutines that writes to one channel will always produce a leak.
Killable must send kill message if user didn't.
@@ -69,7 +69,7 @@ func Every(dur time.Duration, fn func()) {
// channel if timeout occurs.
// TODO: cancel if timeout occurs
func Timeout(duration time.Duration, fn func()) (done <-chan bool) {
ch := make(chan bool)
ch := make(chan bool, 2)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This channel never receives two messages, should we keep the buffer size 1 as well?

@bredov
Copy link
Contributor Author

bredov commented Jan 23, 2014

@rakyll
This channel will always receive two messages, but, agree, it is unlikely that user will ignore done message. Anyway, I would propose either to leave buffer size 2 or set the Timeout function to block and return bool value instead of channel (the latter one seems clearer to me).

@rakyll
Copy link
Owner

rakyll commented Jan 23, 2014

@bredov, sorry, channel receives two messages. It's an implementation problem, I'll provide a fix to ignore the secondary signal. Merging the PR, thanks!

rakyll pushed a commit that referenced this pull request Jan 23, 2014
Make channels buffered to prevent goroutines leak.
@rakyll rakyll merged commit 9f25699 into rakyll:master Jan 23, 2014
@bredov bredov deleted the patch-1 branch January 23, 2014 18:32
@bredov bredov restored the patch-1 branch January 23, 2014 19:57
@bredov bredov deleted the patch-1 branch January 23, 2014 20:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants