Check if channels are closed in the example#244
Merged
nathany merged 3 commits intofsnotify:masterfrom Aug 30, 2018
Merged
Conversation
omeid
reviewed
May 1, 2018
example_test.go
Outdated
| log.Println("modified file:", event.Name) | ||
| } | ||
| case err := <-watcher.Errors: | ||
| if !ok { |
There was a problem hiding this comment.
Check the ok before reading from the event. Essentially, this needs to happen before line 27.
Contributor
Author
There was a problem hiding this comment.
Right :)
Fixed.
omeid
reviewed
May 1, 2018
| } | ||
| case err, ok := <-watcher.Errors: | ||
| log.Println("error:", err) | ||
| if !ok { |
There was a problem hiding this comment.
Same as above, check for close before reading the error. :)
nhooyr
approved these changes
May 12, 2018
matthias-stone
approved these changes
Aug 30, 2018
radu-munteanu
pushed a commit
to radu-munteanu/fsnotify
that referenced
this pull request
Feb 25, 2019
* Check if channels are closed in the example * Check if the channels are closed before printing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is just about adding a check for closed channels to the example https://github.com/fsnotify/fsnotify/blob/master/example_test.go
Without that check the goroutine will keep printing empty errors (nils) & events after the watcher is closed.
See #229