-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
notify: add os.Signal like example to notify documentation
Adds to godoc-generated documentation a very basic example which is similar to the one created in os.Signal package.
- Loading branch information
Pawel Knap
committed
Feb 15, 2015
1 parent
232fb7d
commit 771a99a
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2014-2015 The Notify Authors. All rights reserved. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
package notify_test | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/rjeczalik/notify" | ||
) | ||
|
||
func ExampleWatch() { | ||
// Create a channel which will be used to receive file system notifications. | ||
// The channel must be buffered since the notify package does not block when | ||
// sending events. Thus, if an event is created and there is no one who can | ||
// receive it, the event will be dropped. | ||
c := make(chan notify.EventInfo, 1) | ||
// We are going to watch our working directory recursively trying to catch | ||
// either Create or Write event. | ||
if err := notify.Watch("./...", c, notify.Create, notify.Write); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Block until an event is received. | ||
ei := <-c | ||
log.Println("Got event:", ei) | ||
} |