-
Notifications
You must be signed in to change notification settings - Fork 129
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
Watcher: extend Unwatch arguments with Event
to be unwatched.
#30
Conversation
From the runtime view of point we would need type Watcher interface {
...
Rewatch(path string, old, new Event)
...
} For most implementations it would be enough to: func (x x) Rewatch(path string, _, new Event) {
x.Unwatch(path)
x.Watch(path, new)
} For Windows and FSEvents And notify.Watch("/dir", creat, notify.Create)
notift.Watch("/dir", delet, notify.Delete) would call internally:
instead of:
So basically it enables some optimisations in watch creation/deletion. @pblaszczyk If |
This is more about decreasing number of watched events instead of extend: notify.Watch("p1", ch1, notify.Create | notify.Delete)
notify.Watch("p1", ch2, notify.Create)
notify.Stop(ch1) After last line, you no longer want to monitor deletes, only creates. You can |
notify.Watch("p1", ch1, notify.Create | notify.Delete)
...
// arguments
ch := ch1
newevents := []Event{notify.Create | notify.Delete}
...
//internally, globals per dir
mapechanevent := make(map[chan<- EventInfo]Event) // merged events
eventdiff := []Event
...
eventdiff = geteventdiff(mapechanevent[ch], newevents) // will return []Event{notify.Create, notify.Delete}, because mapechanevent[ch] is empty
newmask := Event{0}
for _, e := range eventdiff
evcounter[e]++
if evcounter[e] > 0 {
newmask |= e
}
}
//internally
Watch("/dir", newmask) notify.Watch("p1", ch2, notify.Create)
|
notify.Watch("p1", ch2, notify.Create)
...
// arguments
ch := ch2
newevents := []Event{notify.Create}
...
//internally, globals per dir
mapechanevent := make(map[chan<- EventInfo]Event) // merged events
eventdiff := []Event
...
eventdiff = geteventdiff(mapechanevent[ch], newevents) // will return []Event{notify.Create},
newmask := Event{0}
for _, e := range eventdiff
evcounter[e]++
// notify.Create = 2
// notify.Delete = 1
if evcounter[e] > 0 {
newmask |= e
}
}
//internally
Watch("/dir", newmask) notify.Stop(ch1)
|
notify.Stop(ch1)
...
// arguments
ch := ch1
...
//internally, globals per dir
mapechanevent := make(map[chan<- EventInfo]Event) // merged events
eventdiff := []Event
...
eventdiff = geteventdiff(mapechanevent[ch], Event(0)) // will return []Event{notify.Create, notify.Delete},
newmask := Event{0}
for _, e := range eventdiff
evcounter[e]--
// notify.Create = 1
// notify.Delete = 0
if evcounter[e] > 0 {
newmask |= e
}
}
//internally
Watch("/dir", newmask) |
That's what |
Ok, it's different approach (requires you to pass current events), but let it be. |
This way you can stop watching only specified events, what is necessary and makes it work as comment says.
It does not change how current implementations work (they ignore the value, and passed is always
All
), but allows it to be utilized.