-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add facilities for signal throttling and debouncing #45
Closed
Closed
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
This file contains 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 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
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.
If I read the description of throttler and debouncer correctly, this here isn't actually a Debouncer, but a trailing Throttler.
If a 100ms Debouncer is called 20 times, every time with a delay of 50ms in-between it should only execute the slot once - 100ms after the last of the twenty signals is received.
The current implementation would call the slot 10 times, after every second signal, where the timeout of 100ms expires each time.
That's what a throttler should do if my understanding is correct.
Please adjust the tests to differentiate between
debouncer and throttler
.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.
Implementation note:
I believe in our current implementation we cannot easily implement a debouncer (or potentially even a trailing throttler).
As a debouncer needs to emit a signal after the timeout expires. However, it cannot do that, as it's not in control of the currently running thread.
The implementation in KDToolBox uses
QTimer
to achieve this.However, QTimer relies on Qt's event-loop to be able to run on the currently active thread:
As we don't have an event-loop to queue even events on we use ConnectionEvaluator as a substitute. So any Debouncer would need a ConnectionEvaluator to which it could queue the emissions.
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.
Ah indeed it is challenging to implement debouncer and throttler in our current implementation , so basically if i am understanding clearly, we need a way that whenever a signal is received, we schedule a task to run after the debounce interval. If another signal is received before the interval expires, we cancel/remove the previously scheduled task and schedule a new one. And something similar with throttler ? We will need a mechanism to queue up the task/slots for debouncer and throttler, or we may use ConnectionEvaluator but need to look once the patch for it lands.