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

Set stopTime to null on start otherwise duration will not work #110

Closed
wants to merge 1 commit into from

Conversation

abrown28
Copy link

Duration was not working for me. I fixed it by setting stopTime to null.

@abrown28 abrown28 changed the title Set stopTime to null on start other wise duration will not work Set stopTime to null on start otherwise duration will not work Sep 13, 2021
@abrown28
Copy link
Author

well it works the first time I go through a start, update, and stop cycle but the next time it's still set to the old stopTime.
I guess creating a new progress bar instead of reusing the old one would probably fix it for me.

@AndiDittrich
Copy link
Member

Hi @abrown28

thanks for your contribution but your code doesn't make any sense since stopTime is already set in the next loc

@abrown28
Copy link
Author

I'm probably not using it in the way you want but here is some example code

const progress = require("cli-progress")

async function test() { 
  const progressBar = new progress.SingleBar({
    format: '{message} | {bar} | {percentage}% || {value}/{total} records || {duration} || {duration_formatted} || {eta_formatted}',
  }, progress.Presets.shades_classic);

  for(let i=0; i<10; ++i) {
    progressBar.start(100, 0, {
      message: "Testing progress bar when reused"
    })

    for(let j=0; j<100; ++j) {
      progressBar.update(j+1)
      await sleep(1)
    }

    progressBar.stop();
  }
}

async function sleep(seconds) {
  return new Promise(resolve => setTimeout(resolve, seconds*100));
}

test()

When I run the above I get the following:

Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 11 || 11s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s
Testing progress bar when reused | ████████████████████████████████████████ | 100% || 100/100 records || 0 || 0s || 0s

The duration and duration_formatted only worked the first time. That's what I'm seeing when I pull it with npm

@AndiDittrich
Copy link
Member

the fix has already been provided in #101 but it's not release yet

@AndiDittrich
Copy link
Member

v3.9.1 is out including the changes within master (patch #101 )

@abrown28
Copy link
Author

abrown28 commented Sep 15, 2021 via email

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.

2 participants