Skip to content

Commit

Permalink
notify: add os.Signal like example to notify documentation
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var estr = map[Event]string{

// String implements fmt.Stringer interface.
func (e *event) String() string {
return e.Event().String() + `, "` + e.Path() + `"`
return e.Event().String() + `: "` + e.Path() + `"`
}

// Kind gives generic event type of the EventInfo.Event(). The purpose is to
Expand Down
28 changes: 28 additions & 0 deletions example_test.go
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)
}

0 comments on commit 771a99a

Please sign in to comment.