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
Document when with_key
callbacks get invoked, and in which order
#578
Open
joshtriplett
wants to merge
1
commit into
console-rs:main
Choose a base branch
from
joshtriplett:document-key-ordering
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
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
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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.
What's this for? I'm not all that comfortable with making this last sentence explicit. Changing the
ProgressBar
duringProgressTracker::write()
is definitely not something I had in mind and really want to spend time considering as something that I should keep working.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 also think this might get into locking issues? Like, the
ProgressTracker
impl gets immutable access to the&ProgressState
, which lives inside theBarState
which is inside anArc<Mutex<_>>
inside theProgressBar
.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 reason this works right now seems to be that (fortunately) the first thing the implementation does is to update its last-updated time with the current one before continuing with the update. Future calls to
tick()
will now immediately bounce off as the update seems to have just been done.With that said, we also use the ticker-thread which may change the codepath, but the above is what I could gather by looking at the code.
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.
ProgressBar::set_position()
is rate-limited, yes, likeProgressBar::inc()
, butProgressBar::tick()
isn't. So this is pretty nuanced, and not something that I want to guarantee to this level of detail going forward.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.
Anyway, it would be interesting to know why you want to do this. Presumably you can pass a
ProgressBar
clone into whatever thing that is making progress and call that outside of theProgressTracker
implementation.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's a great question: what problem is calling
set_position()
on a clone of the progress-bar from within thewith_key()
callback actually solving?We have an ongoing operation which keeps updating an atomic counter which should be mapped to the
pos
of the progress bar. In order to do it with the current API it's necessary to use a callback which typically is more involved and noisy than passing a reference to an atomic down to where it needs to be. That noisiness was avoided by callingset_position()
from within thewith_key()
callback.An alternative solution could be to make the atomic counter that's used within the progress bar directly accessible - we use an auto-ticker so communicating via shared state would (seemingly) work.
I hope this context helps.