Giter Club home page Giter Club logo

Comments (7)

Naatan avatar Naatan commented on June 6, 2024

Note adding wait groups makes no difference.

from mpb.

vbauerster avatar vbauerster commented on June 6, 2024

It just happens that RemoveBar method never considered "remove after completion done" case, there is nothing to do with thread safety. In fact it is removing the bar from the heap container, but too late in this particular case. It's very tricky to keep track, if initial intention (remove or keep) is unknown. So I would better rename this method to something like RemoveWhile and better add an option to auto-remove bar after completion. This way, there is no need to call defer p.RemoveBar.

from mpb.

Naatan avatar Naatan commented on June 6, 2024

Is there a way to set the initial intention? ie. remove on completion.

from mpb.

vbauerster avatar vbauerster commented on June 6, 2024

Not yet, but I'm going to add via optional BarOption.
User api would be: p.AddBar(total, mpb.BarRemoveOnComplete()). As for current p.RemoveBar, I'm going to rename it to p.Abort, because imo it would be clear indication what the method does.

from mpb.

vbauerster avatar vbauerster commented on June 6, 2024

I did some refactoring, so following code should work as you wish.

const sleep = 100 * time.Millisecond

func main() {
	p := mpb.New()
	
	b1 := p.AddBar(int64(100), mpb.BarRemoveOnComplete(),
			mpb.PrependDecorators(decor.StaticName("bar1", 0, 0)))
			
	go func() {
		go func() {
			time.Sleep(10 * sleep)
			b2 := p.AddBar(int64(100), mpb.BarRemoveOnComplete(),
					mpb.PrependDecorators(decor.StaticName("bar2", 0, 0)))
					
			for !b2.Completed() {
				b2.IncrBy(10) // fastest
				time.Sleep(sleep)
			}
		}()

		for !b1.Completed() {
			b1.IncrBy(2) // second fastest
			time.Sleep(sleep)
		}
	}()

	go func() {
		b3 := p.AddBar(int64(100), mpb.BarRemoveOnComplete(),
				mpb.PrependDecorators(decor.StaticName("bar3", 0, 0)))
				
		for !b3.Completed() {
			b3.IncrBy(1) // slowest
			time.Sleep(sleep)
		}
	}()

	p.Wait()
}

from mpb.

Naatan avatar Naatan commented on June 6, 2024

Thanks @vbauerster! I'll give this a go next Monday-ish.

from mpb.

Naatan avatar Naatan commented on June 6, 2024

Tried it today, seems to be working well! I noticed some slight glitches when firing progressbars that are then quickly removed, but I'll try to come up with a test case for that and report it separately.

from mpb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.