github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/exp/fsnotify/example_test.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build !plan9,!solaris 6 7 package fsnotify_test 8 9 import ( 10 "log" 11 12 "golang.org/x/exp/fsnotify" 13 ) 14 15 func ExampleNewWatcher() { 16 watcher, err := fsnotify.NewWatcher() 17 if err != nil { 18 log.Fatal(err) 19 } 20 21 go func() { 22 for { 23 select { 24 case ev := <-watcher.Event: 25 log.Println("event:", ev) 26 case err := <-watcher.Error: 27 log.Println("error:", err) 28 } 29 } 30 }() 31 32 err = watcher.Watch("/tmp/foo") 33 if err != nil { 34 log.Fatal(err) 35 } 36 }