New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listening should be in a goroutine #346

Merged
merged 2 commits into from Aug 11, 2015
Jump to file or symbol
Failed to load files and symbols.
+12 −6
Diff settings

Always

Just for now

View
@@ -726,6 +726,18 @@ func (c *Client) Stats(opts StatsOptions) (retErr error) {
close(errC)
}()
+ quit := make(chan struct{})
+ defer close(quit)
+ go func() {
+ // block here waiting for the signal to stop function
+ select {
+ case <-opts.Done:
+ readCloser.Close()
+ case <-quit:
+ return
+ }
+ }()
+

This comment has been minimized.

@tonicbupt

tonicbupt Aug 11, 2015

Contributor

@fsouza done... I just knew closing a channel can still go to <-quit ...

@tonicbupt

tonicbupt Aug 11, 2015

Contributor

@fsouza done... I just knew closing a channel can still go to <-quit ...

decoder := json.NewDecoder(readCloser)
stats := new(Stats)
for err := decoder.Decode(&stats); err != io.EOF; err = decoder.Decode(stats) {
@@ -734,12 +746,6 @@ func (c *Client) Stats(opts StatsOptions) (retErr error) {
}
opts.Stats <- stats
stats = new(Stats)
- select {
- case <-opts.Done:
- readCloser.Close()
- default:
- // Continue
- }
}
return nil
}