Skip to content
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

Don't conflate ticking with updating estimates #434

Merged
merged 3 commits into from
May 24, 2022

Conversation

chris-laplante
Copy link
Collaborator

Fixes #433

f() will run for a user-determined amount of time, so the 'now' that was
passed into the function isn't really valid after the point when f()
returns.
@chris-laplante chris-laplante requested a review from djc May 19, 2022 16:20
src/state.rs Outdated
@@ -77,36 +77,37 @@ impl BarState {

pub(crate) fn update(&mut self, now: Instant, f: impl FnOnce(&mut ProgressState)) {
f(&mut self.state);
self.tick(now);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a big change in behavior? Why do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that the whole reason the user is calling update is because they want to do something specific with ProgressState that isn't already covered by the existing API. I can't imagine they'd want to do something very custom + tick. Though I agree it is a change in behavior, so I could back out this change if you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem like a big deal to me to tick in this particular case? It's not like ticking is expensive, we currently tick for most other kinds of updates IIRC.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll back that change out after dinner tonight.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was expecting that you'd change everything back to tick, like before, but you only backed this particular change out. I'm still not sure that makes sense?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I wasn't clear. Commit 0440689 is just something else I noticed while I was fixing the main issue, so it's not really related. Try running the yarnish example with and without my commit da9e432. You'll see that without my changes it ticks too fast. This is because even just setting the message/prefix increments the tick, which I doubt is what users are expecting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that the old code was somewhat lazily calling tick even when in certain cases all it wanted to do was update_estimate_and_draw (e.g for message and prefix). It just so happened that the old condition if self.ticker.is_none() || self.state.tick == 0 mostly made it do the right thing. My changes here are intended to make the difference explicit.

tests/render.rs Show resolved Hide resolved
@djc djc merged commit d3e280e into console-rs:main May 24, 2022
@fabricedesre
Copy link

It would be nice to get a new published version with this fix. When is the next rc planned?

@djc
Copy link
Member

djc commented May 24, 2022

We don't really plan rcs, we can just do one now.

@djc
Copy link
Member

djc commented May 24, 2022

@fabricedesre out of curiosity, what are you using indicatif for?

@fabricedesre
Copy link

@fabricedesre out of curiosity, what are you using indicatif for?

I use it in this command line tool: https://github.com/capyloon/nutria/tree/main/builder to display the download progress of prebuilt binaries. That can be slow when the ipfs gateway is not in great shape, so I'd like to use [enable_steady_tick](https://docs.rs/indicatif/0.16.2/indicatif/struct.ProgressBar.html#method.enable_steady_tick) but before this fix it was no t updating remaining time properly when the download was slow / waiting for data.

@djc
Copy link
Member

djc commented May 24, 2022

#435 has the version bump, will publish once that's merged.

@MarijnS95
Copy link
Contributor

fn tick() in the documentation still mentions This automatically happens on any other change to a progress bar.:

/// This automatically happens on any other change to a progress bar.
pub fn tick(&self) {

@chris-laplante
Copy link
Collaborator Author

fn tick() in the documentation still mentions This automatically happens on any other change to a progress bar.:

Good catch, thanks. I will submit a PR to update the documentation.

@chris-laplante chris-laplante deleted the cpl/fix-ticker-inc branch June 16, 2022 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spinners no longer advance
4 participants