Giter Club home page Giter Club logo

Comments (3)

nilsbeck avatar nilsbeck commented on July 22, 2024

To be able to copy paste:

`package main

import (
"fmt"
"math/rand"
"sync"
"time"

"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"

)

func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg))
total := 100
numBars := 3
wg.Add(numBars)

for i := 0; i < numBars; i++ {
	name := fmt.Sprintf("Bar#%d:", i)
	bar := p.AddBar(int64(total),
		mpb.BarID(i),
		mpb.BarOptional(mpb.BarRemoveOnComplete(), true),
		mpb.PrependDecorators(
			decor.Name(name),
		),
		mpb.AppendDecorators(
			decor.Any(func(s decor.Statistics) string {
				return fmt.Sprintf("completed: %v", s.Completed)
			}, decor.WCSyncSpaceR),
			decor.Any(func(s decor.Statistics) string {
				return fmt.Sprintf("aborted: %v", s.Aborted)
			}, decor.WCSyncSpaceR),
			decor.OnComplete(decor.NewPercentage("%d", decor.WCSyncSpace), "done"),
			decor.OnAbort(decor.NewPercentage("%d", decor.WCSyncSpace), "ohno"),
		),
	)
	go func() {
		defer wg.Done()
		rng := rand.New(rand.NewSource(time.Now().UnixNano()))
		max := 100 * time.Millisecond
		for i := 0; bar.IsRunning(); i++ {
			if bar.ID() == 2 && i >= 42 {
				go bar.Abort(false)
			}
			time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
			bar.Increment()
		}
	}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()

}`

from mpb.

vbauerster avatar vbauerster commented on July 22, 2024

I was able to reproduce with change you mentioned and disabled bar.Abort case:

go bar.Abort(false)

Fix commit added to the master branch. Can you please confirm it works for you?

from mpb.

nilsbeck avatar nilsbeck commented on July 22, 2024

Hey,
yes. That fixes it! I also tested it my own example (my code base) which is slightly more complex than the example. and it is working there as well!

Thank you for being so responsive and fixing this!

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.