From: Alexey Kazakov Date: Thu, 30 Aug 2018 22:02:26 +0000 (-0700) Subject: Check if channels are closed in the example (#244) X-Git-Tag: v1.7.2~165 X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=ccc981bf80385c528a65fbfdd49bf2d8da22aa23;p=fsnotify.git Check if channels are closed in the example (#244) * Check if channels are closed in the example * Check if the channels are closed before printing --- diff --git a/example_test.go b/example_test.go index 700502c..b4f9f95 100644 --- a/example_test.go +++ b/example_test.go @@ -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) } }