piotrmurach / tty-progressbar

Display a single or multiple progress bars in the terminal.
https://ttytoolkit.org
MIT License
424 stars 24 forks source link

TTY::ProgressBar::Multi finishes too early #22

Closed Leopard2A5 closed 7 years ago

Leopard2A5 commented 7 years ago

Hi!

First of all: nice gem! Unfortunately i found an issue when i tried it out: I changed your TTY::ProgressBar::Multi example by adding a third sub-progressbar with a different total than the other two:

require 'tty-progressbar'

bars = TTY::ProgressBar::Multi.new("main [:bar] :percent")

bar1 = bars.register("one [:bar] :percent", total: 15)
bar2 = bars.register("two [:bar] :percent", total: 15)
bar3 = bars.register("thr [:bar] :percent", total: 45)

bars.start

th1 = Thread.new { 15.times { sleep(0.1); bar1.advance } }
th2 = Thread.new { 15.times { sleep(0.1); bar2.advance } }
th3 = Thread.new { 45.times { sleep(0.1); bar3.advance } }

[th1, th2, th3].each { |t| t.join }

That consistently (unless by coincidence the scheduling gives me the same result every time) gives me the following output:

ruby progressbar.rb
┌ main [===========================================================================] 100%
├── thr [================                             ] 38%
├── two [===============] 100%
└── one [===============] 100%

Hope this helps :)

piotrmurach commented 7 years ago

Hey Rene,

Thanks for using the library and reporting this bug!

The main issue was that multi bar was finishing on the first :done event sent from any registered progress bars, which is exactly illustrated by your example. I have completely changed how the events registration and notification works for multi bars so this issues shall be no more.

piotrmurach commented 7 years ago

Released v0.12.1 with the fix.