func (h *PbHandler) WaitProgress() {
	h.pbPool.Wait()
}
WaitProgress wait the progress bar to complete
package taskutils
import (
	"context"
	"os"
	"sync"
	"time"
	"github.com/qingstor/noah/pkg/progress"
	"github.com/vbauerster/mpb/v5"
	"github.com/vbauerster/mpb/v5/decor"
	"golang.org/x/crypto/ssh/terminal"
)
const (
	widStatus          = 20
	widStat            = 40
	widBarDefault      = 40
	widTerminalDefault = 120
)
type barGroup struct {
	sync.Mutex
	bars map[string]*mpb.Bar
}
type ClearFunc func()
type PbHandler struct {
	pbPool *mpb.Progress
	bGroup *barGroup
	closeSig chan struct{}
	nameFilter func(string) string
}
func NewHandler(c context.Context) (*PbHandler, ClearFunc) {
	terminalWidth, _, err := terminal.GetSize(int(os.Stdout.Fd()))
	if err != nil {
		terminalWidth = widTerminalDefault
	}
	nameWidth, barWidth := calBarSize(terminalWidth)
	closeChan := make(chan struct{})
	pbGroup := &barGroup{
		bars: make(map[string]*mpb.Bar),
	}
	ctx, cancel := context.WithCancel(c)  
	pbPool := mpb.NewWithContext(ctx, mpb.WithWidth(barWidth))
	ph := &PbHandler{
		pbPool:   pbPool,
		bGroup:   pbGroup,
		closeSig: closeChan,
		nameFilter: func(s string) string {
			return truncateBefore(s, nameWidth)
		},
	}
	return ph, func() {
		close(closeChan)
		cancel()
		pbGroup.Lock()
		defer pbGroup.Unlock()
		for id, bar := range pbGroup.bars {
			bar.Abort(true)
			delete(pbGroup.bars, id)
		}
		progress.ClearStates()
	}
}
func (h *PbHandler) StartProgress(d time.Duration) {
	tc := time.NewTicker(d)
	for {
		select {
		case <-tc.C:
			h.bGroup.Lock()
			for taskID, state := range progress.GetStates() {
				if state.IsListType() {
					continue
				}
				bar := h.bGroup.GetBarByID(taskID)
				if bar != nil {
					bar.SetCurrent(state.Done)
					bar.DecoratorEwmaUpdate(d)
					continue
				}
				if state.Finished() {
					continue
				}
				b := h.addBarByState(state)
				b.SetCurrent(state.Done)
				b.DecoratorEwmaUpdate(d)
				h.bGroup.SetBarByID(taskID, b)
			}
			h.bGroup.Unlock()
		case <-h.closeSig:
			tc.Stop()
			h.WaitProgress()  
			return
		}
	}
}