-
Notifications
You must be signed in to change notification settings - Fork 44
Implement debounce time for automatic reloading #117
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Although (I think) I understand why you used both the mutex and the debouncer, I don't think this is necessary - even though the docs for the debouncer say that it filters out only duplicates, it actually (in practice) filters out all but the last event within the timeframe, even if the other events weren't duplicates. You can tell this if you look at the code, but also if you just look at the type signature for
EventDebouncer- it doesn't requireT: PartialEq.So I think we can probably just get rid of
last_eventaltogether and just dodebouncer.put(event)and that'll be a lot cleaner and do more what we want.Also, as a sidenote: I noticed that the
notifycrate (which we use for watching the filesystem) has its own debouncer crate(s), so those might be cleaner or better suited for what we're doing here? Probably doesn't matter, though, either is probably fine.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.
EventDebouncer::putrequiresPartialEqand does the deduplication, see https://docs.rs/debounce/latest/src/debounce/buffer.rs.html#78. Debouncing is pretty simple to implement, so there it probably doesn't matter which crate is used for this (or if it's hand-written), but yeahnotify-debouncer-miniis probably a better choice here, I didn't know it existed.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.
wait, yeah you're totally right. i was definitely confused as to what part of the code did what.
i'm still not crazy about the debouncer + mutex, but it does the job. we can look into switching crates if it turns out this one isn't fulfilling its purpose for whatever reason
Uh oh!
There was an error while loading. Please reload this page.
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.
Well, this is kind of weird. The callback expected by by
notify-debouncer-minitakes events in this form:This seems kind of useless? Am I not seeing something here?
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.
notify-debouncer-fullgives proper events, but to me it seems really overbuilt for this job.Uh oh!
There was an error while loading. Please reload this page.
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 don't think there is a good way to write this without a mutex. It definitely needs synchronization, since the timeout might expire the same moment that a new event comes in. The only alternative I can think would be to replace it atomically, but that's not possible without allocating it, since
RenderErroris 56 bytes.Also in reality the mutex will barely have any contention, so I think this is fine.
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.
Yeah, it'll be fine - my comment about the mutex was more so noting that the debouncer already contains a mutex, so we're using 2 for the job of 1, but they're both going to be in very low contention, so that's not really an issue (like you said).
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.
That was also not the right link 🙃
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.
The extra mutex could be removed by calling
putwith the event wrapped in a newtype whosePartialEqalways returnstrue, but yuck :D