Permalink
Browse files

Use buffered file events channel for Dir

  • Loading branch information...
mrnugget committed Mar 19, 2013
1 parent 65c0764 commit 7c4e8b47c55320dfb5a9cb88c74c4ab693bc777c
Showing with 7 additions and 7 deletions.
  1. +3 −1 watchgopher/dir.go
  2. +4 −6 watchgopher/dir_test.go
View
@@ -7,9 +7,11 @@ import (
"path"
)
+const fileChanBuf = 500
+
func NewDir(path string) (d *Dir) {
files := make(map[string]os.FileInfo)
- events := make(chan *fsnotify.FileEvent)
+ events := make(chan *fsnotify.FileEvent, fileChanBuf)
return &Dir{path, files, events}
}
View
@@ -41,11 +41,6 @@ func TestEvents(t *testing.T) {
err = ioutil.WriteFile(testfilepath, []byte("Hello World!"), 0644)
checkErr(t, err)
- createev := <-dir.Events
- if createev.Name != testfilepath && !createev.IsCreate() {
- t.Fatal("Did not receive the right event")
- }
-
time.Sleep(1 * time.Millisecond)
_, ok := dir.Files[testfilepath]
@@ -56,7 +51,10 @@ func TestEvents(t *testing.T) {
err = os.Remove(testfilepath)
checkErr(t, err)
- time.Sleep(1 * time.Millisecond)
+ createev := <-dir.Events
+ if createev.Name != testfilepath && !createev.IsCreate() {
+ t.Fatal("Did not receive the right event")
+ }
deleteev := <-dir.Events
if deleteev.Name != testfilepath && !deleteev.IsDelete() {

0 comments on commit 7c4e8b4

Please sign in to comment.