Skip to content

CleanOnFinish doesn't work as intended in pool #223

@sewnie

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

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