-
Notifications
You must be signed in to change notification settings - Fork 113
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 custom button refresh time #70
Open
boppy
wants to merge
2
commits into
p-e-w:master
Choose a base branch
from
boppy:add-cycle-timeouts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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.
Why are there two nested timeouts here? I don't understand this part at all.
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.
Yes, that's the tricky part... But after some tries, it is the easiest way I found.
The first wrapping
GLib.timeout_add_seconds
is just to emulate a "window.setTimeout" event. It only runs once (returningfalse
at line 154) setting the "current" line once. It takes the (current) sum of seconds as a Timeout, so next strings appear after the correct timeout.Then the second timeout always has a fixed
fullsec
since the initial iteration over the lines is done and the full sum of seconds is known. This "full sum of seconds" is the timeout for EACH of the lines. Image:Line A is shown directly (because
fullsec
is0
on first run), Line B is shown0+1
seconds later, Line C is shown0+1+3
seconds later. After this first launch of the lines, the timeout does not change anymore for any of the lines, because we used the different timeouts in the first loop, so every message is displayed every0+1+3+2
seconds from now on.As a native German speaker I hope that I was able to describe the idea good enough to make it understandable. If not so, just keep asking... ;)
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.
So to summarize, each line has its own independent periodic timeout with interval equal to the total timeout of all lines, and each of those timeouts is offset by another timeout equal to the sum of timeouts of all lines before it.
That's a nice idea, but it doesn't quite work. The problem is that Desktop Linux is not a realtime operating system, and functions like
timeout_add_seconds
don't guarantee anything with respect to wall clock time (this is actually mentioned in the GLib documentation). So in the long run, the individual_cycleTimeouts
can get out of sync, to the point where the order in which the lines are displayed is changed. This can't be allowed to happen.See the
_update
function in the same file for an approach that solves this problem. At the end of each cycle, a timeout is set that recursively invokes the function. The length of the timeout can depend on the cycle, and thus on the line. This also means that only one timeout is active at any given time, which saves resources.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.
check!
check! I got the "recalculation" thing from the docs wrong... 😞
check!
I'll continue optimizing. Thanks for taking the time to respond.