Skip to content

Instantly share code, notes, and snippets.

@elbaro
Created February 6, 2018 15:40
Show Gist options
  • Select an option

  • Save elbaro/c9660c0b242f25857b90b2591aa6831a to your computer and use it in GitHub Desktop.

Select an option

Save elbaro/c9660c0b242f25857b90b2591aa6831a to your computer and use it in GitHub Desktop.
mpb test example
package main
import (
"fmt"
"sync"
"time"
"github.com/vbauerster/mpb"
"github.com/vbauerster/mpb/decor"
)
func main() {
var wg sync.WaitGroup
p := mpb.New(mpb.WithWaitGroup(&wg))
total := 100
numBars := 5
gb := p.AddBar(
int64(numBars),
mpb.AppendDecorators(
decor.ETA(2, 0),
decor.Percentage(5, 0),
),
)
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
decor.StaticName(name, 0, 0),
decor.Percentage(3, decor.DSyncSpace),
),
mpb.AppendDecorators(
decor.ETA(2, 0),
),
)
go func(i int) {
defer wg.Done()
for j := 0; j < total; j++ {
time.Sleep(time.Duration((i+1)*(i+1)*2) * time.Millisecond)
bar.Increment()
}
gb.Increment()
}(i)
}
p.Stop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment