Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First working, non-recursive runtime (part 1) #39

Merged
merged 8 commits into from
Oct 18, 2014
Prev Previous commit
Next Next commit
Rename Fanin -> Dispatch
  • Loading branch information
rjeczalik committed Oct 18, 2014
commit 3ed82e16edaea532b648e75a99083c2374082f53
2 changes: 1 addition & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func NewRuntimeWatcher(w Watcher, fs fs.Filesystem) *Runtime {
}
r.i = i
}
r.i.Fanin(c, r.stop)
r.i.Dispatch(c, r.stop)
go r.loop()
return r
}
Expand Down
8 changes: 4 additions & 4 deletions test/r.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type FuncType string
const (
Watch = FuncType("Watch")
Unwatch = FuncType("Unwatch")
Fanin = FuncType("Fanin")
Dispatch = FuncType("Dispatch")
Rewatch = FuncType("Rewatch")
RecursiveWatch = FuncType("RecursiveWatch")
RecursiveUnwatch = FuncType("RecursiveUnwatch")
Expand Down Expand Up @@ -204,9 +204,9 @@ func (s *Spy) Unwatch(p string) (err error) {
return
}

// Fanin implements notify.Watcher interface.
func (s *Spy) Fanin(chan<- notify.EventInfo, <-chan struct{}) {
*s = append(*s, Call{F: Fanin})
// Dispatch implements notify.Watcher interface.
func (s *Spy) Dispatch(chan<- notify.EventInfo, <-chan struct{}) {
*s = append(*s, Call{F: Dispatch})
}

// Rewatch implements notify.Rewatcher interface.
Expand Down
4 changes: 2 additions & 2 deletions test/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestEI(t *testing.T) {
[]interface{}{"will get overwritten", notify.Delete, "/", notify.Write},
},
{
ei{i: 0, p: "/tmp", e: notify.All, f: Fanin},
[]interface{}{"/home", EI(".", notify.All, EI("/tmp", Watch)), Fanin},
ei{i: 0, p: "/tmp", e: notify.All, f: Dispatch},
[]interface{}{"/home", EI(".", notify.All, EI("/tmp", Watch)), Dispatch},
},
}
for i, cas := range cases {
Expand Down
4 changes: 2 additions & 2 deletions test/w.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (w *w) Close() error {
// the time test took has exceeded default global timeout.
func (w *w) ExpectEvent(wr notify.Watcher, ei []notify.EventInfo) {
done, c, stop := make(chan error), make(chan notify.EventInfo, len(ei)), make(chan struct{})
wr.Fanin(c, stop)
wr.Dispatch(c, stop)
defer close(stop)
go func() {
for _, ei := range ei {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (w *w) ExpectEvent(wr notify.Watcher, ei []notify.EventInfo) {
// order they were either defined or assigned to the cases.
func (w *w) ExpectEvents(wr notify.Watcher, cases map[notify.EventInfo][]notify.Event) {
done, c, stop := make(chan error), make(chan notify.EventInfo, len(cases)), make(chan struct{})
wr.Fanin(c, stop)
wr.Dispatch(c, stop)
defer close(stop)
go func() {
// Sort keys to ensure cases are executed in chronological order.
Expand Down
6 changes: 3 additions & 3 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type Watcher interface {
// 1:M producer-consumer model.
Unwatch(path string) error

// Fanin requests to fan in all events from all the created watchers into c.
// Dispatch requests to fan in all events from all the created watchers into c.
// It is guaranteed the c is non-nil. All unexpected events are ignored.
//
// The Fanin method is called once on package init by the notify runtime.
// The Dispatch method is called once on package init by the notify runtime.
//
// The stop channel is closed when the notify runtime is stopped and is no
// longer receiving events sent to c.
Fanin(c chan<- EventInfo, stop <-chan struct{})
Dispatch(c chan<- EventInfo, stop <-chan struct{})
}

// Rewatcher provides an interface for modyfing existing watch-points, like
Expand Down
4 changes: 2 additions & 2 deletions watcher_fsnotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (fs fsnotify) Unwatch(p string) error {
return fs.w.Remove(p)
}

// Fanin implements notify.Watcher interface.
func (fs fsnotify) Fanin(c chan<- EventInfo, stop <-chan struct{}) {
// Dispatch implements notify.Watcher interface.
func (fs fsnotify) Dispatch(c chan<- EventInfo, stop <-chan struct{}) {
go func() {
for {
select {
Expand Down
4 changes: 2 additions & 2 deletions watcher_inotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ func (i *inotify) Unwatch(p string) error {
return inotifyunwatch(p)
}

// Fanin implements notify.Watcher interface.
func (i *inotify) Fanin(c chan<- EventInfo, stop <-chan struct{}) {
// Dispatch implements notify.Watcher interface.
func (i *inotify) Dispatch(c chan<- EventInfo, stop <-chan struct{}) {
i.wg.Wait() // Waits for close of previous loop() - only for test purpose.
i.c = c
go loop(stop)
Expand Down
4 changes: 2 additions & 2 deletions watcher_kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ func isdir(p string) (bool, error) {
return fi.IsDir(), nil
}

// Fanin implements `Watcher` interface.
func (k *kqueue) Fanin(c chan<- EventInfo, stop <-chan struct{}) {
// Dispatch implements `Watcher` interface.
func (k *kqueue) Dispatch(c chan<- EventInfo, stop <-chan struct{}) {
go func() {
for {
select {
Expand Down