Skip to content
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

Merged
merged 3 commits into from Aug 30, 2018

Conversation

alexeykazakov
Copy link
Contributor

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

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 {
Copy link

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.

Copy link
Contributor Author

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 {
Copy link

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. :)

@nathany nathany merged commit ccc981b into fsnotify:master 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants