Skip to content

Commit

Permalink
Check if channels are closed in the example (fsnotify#244)
Browse files Browse the repository at this point in the history
* Check if channels are closed in the example

* Check if the channels are closed before printing
  • Loading branch information
alexeykazakov authored and radu-munteanu committed Feb 25, 2019
1 parent fb86cf7 commit 716950c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions example_test.go
Expand Up @@ -23,12 +23,18 @@ func ExampleNewWatcher() {
go func() {
for {
select {
case event := <-watcher.Events:
case event, ok := <-watcher.Events:
if !ok {
return
}
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err := <-watcher.Errors:
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
Expand Down

0 comments on commit 716950c

Please sign in to comment.