-
Notifications
You must be signed in to change notification settings - Fork 229
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
Remove channel in favour of accepting Fn
in Watcher constructors
#214
Conversation
This implements the changes described in notify-rs#213. This PR is a **work-in-progress**. TODO: - [x] Make API change. - [x] Update inotify watcher. - [x] Update poll watcher. - [ ] Update fsevents watcher. - [ ] Update windows watcher.
Oh also, I don't have access to macOS or Windows at the moment - if anyone has access to either of those platforms and would like to include them in this PR feel free! Otherwise it might be a while until I can address this. |
OK, I've managed to update the |
By boxing the EventFn field within the inotify EventLoop we can stop the need to regenerate the item's layout each time a change occurs within the user's EventFn implementation.
70f5131
to
ec9c57c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a cursory review, but I don't really understand notify's internals, so some high-level bits might be missing
src/lib.rs
Outdated
|
||
impl<F> EventFn for F | ||
where | ||
F: 'static + Fn(Result<Event>) + Send + Sync {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use something like type OnEvent = dyn Fn(Result<Event>) + Send + Sync + 'static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip, but does this matter much? Are there bigger motivations for using the type alias, or is it mostly just to avoid having to prefix dyn
everywhere? I'm currently leaning towards leaving this as it is, but want to check I'm not missing some subtly incurred cost by leaving it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s not to avoid dyn, it’s to avoid an extra trait and just lean on existing Fn
This adds the indirection of dynamic dispatch as early as possible within the `Watcher` implementations to avoid generating large amounts of code for calls to `Watcher` methods with different argument types. Also addresses some synchronisation issues raised by @matklad in some examples and tests and changes them to match their original behaviour.
Thanks again @matklad, I think I've addressed everything you have raised. If there is nothing else, I might merge this within the next couple of days. A nice follow-up to this PR might be to see if crossbeam is necessary at all any longer. It maybe be possible to remove the remaining use cases in favour of std in order to shave off a dependency? Edit: particularly as it is no longer publicly exposed. |
This implements the changes described in #213.
This PR is a work-in-progress.TODO:
Closes #213.
Closes #160.