Skip to content

Commit

Permalink
Check if channels are closed in the example (#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 nathany committed Aug 30, 2018
1 parent 1f285c6 commit ccc981b
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 ccc981b

Please sign in to comment.