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.