Skip to content

CleanOnFinish doesn't work as intended in pool #223

Description

@sewnie
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions