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

CleanOnFinish doesn't work as intended in pool #223

Open
apprehensions opened this issue Sep 28, 2024 · 0 comments
Open

CleanOnFinish doesn't work as intended in pool #223

apprehensions opened this issue Sep 28, 2024 · 0 comments

Comments

@apprehensions
Copy link

apprehensions commented Sep 28, 2024

package main

import (
	"sync"
	"time"

	"github.com/cheggaaa/pb/v3"
)

func main() {
	count := 5
	var wg sync.WaitGroup
	wg.Add(count)

	// pool requires atleast one bar to start
	root := pb.New(count)
	pool := pb.NewPool(root)
	_ = pool.Start()
	
	for i := 0; i < count; i++ {
		go func() {
			defer func() {
				root.Increment()
				defer wg.Done()
			}()

			bar := pb.StartNew(1000)
			bar.Set(pb.CleanOnFinish, true)
			pool.Add(bar)

			for i := 0; i < 1000; i++ {
				time.Sleep(time.Millisecond)
				bar.Increment()
			}

			bar.Finish()
		}()
	}

	wg.Wait()
	pool.Stop()
}

Got:

5 / 5 [-------------------------------------------------------------------->] 100.00% ? p/s
1000 / 1000 [------------------------------------------------------------] 100.00% 1076 p/s
1000 / 1000 [------------------------------------------------------------] 100.00% 1076 p/s
1000 / 1000 [------------------------------------------------------------] 100.00% 1076 p/s
1000 / 1000 [------------------------------------------------------------] 100.00% 1076 p/s
1000 / 1000 [------------------------------------------------------------] 100.00% 1076 p/s

Expected:

5 / 5 [-------------------------------------------------------------------->] 100.00% ? p/s
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

No branches or pull requests

1 participant