예제 #1
0
func (t *InotifyTracker) NewWatcher() (*fsnotify.Watcher, error) {
	t.mux.Lock()
	defer t.mux.Unlock()
	w, err := fsnotify.NewWatcher()
	if err == nil {
		t.watchers[w] = true
	}
	return w, err
}
예제 #2
0
func ExampleNewWatcher() {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		for {
			select {
			case ev := <-watcher.Event:
				log.Println("event:", ev)
			case err := <-watcher.Error:
				log.Println("error:", err)
			}
		}
	}()

	err = watcher.Watch("/tmp/foo")
	if err != nil {
		log.Fatal(err)
	}
}