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
6
7package fsnotify_test
8
9import (
10	"log"
11
12	"github.com/fsnotify/fsnotify"
13)
14
15func ExampleNewWatcher() {
16	watcher, err := fsnotify.NewWatcher()
17	if err != nil {
18		log.Fatal(err)
19	}
20	defer watcher.Close()
21
22	done := make(chan bool)
23	go func() {
24		for {
25			select {
26			case event := <-watcher.Events:
27				log.Println("event:", event)
28				if event.Op&fsnotify.Write == fsnotify.Write {
29					log.Println("modified file:", event.Name)
30				}
31			case err := <-watcher.Errors:
32				log.Println("error:", err)
33			}
34		}
35	}()
36
37	err = watcher.Add("/tmp/foo")
38	if err != nil {
39		log.Fatal(err)
40	}
41	<-done
42}
43