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
Check if channels are closed in the example #244
Conversation
example_test.go
Outdated
log.Println("event:", event) | ||
if event.Op&fsnotify.Write == fsnotify.Write { | ||
log.Println("modified file:", event.Name) | ||
} | ||
case err := <-watcher.Errors: | ||
if !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the ok
before reading from the event
. Essentially, this needs to happen before line 27.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right :)
Fixed.
example_test.go
Outdated
log.Println("error:", err) | ||
if !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, check for close before reading the error. :)
* Check if channels are closed in the example * Check if the channels are closed before printing
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