Codebase list golang-github-vbauerster-mpb / 5bbd0d1
examples use v5 Vladimir Bauer 6 years ago
36 changed file(s) with 151 addition(s) and 115 deletion(s). Raw diff Collapse all Expand all
00 module github.com/vbauerster/mpb/_examples/barExtender
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
5
6 replace github.com/vbauerster/mpb/v5 => /Users/vbauer/gohack/github.com/vbauerster/mpb/v5
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v4"
10 "github.com/vbauerster/mpb/v4/decor"
9 "github.com/vbauerster/mpb/v5"
10 "github.com/vbauerster/mpb/v5/decor"
1111 )
1212
1313 func main() {
2323 fmt.Fprintf(w, "Bar id: %d has been completed\n", s.ID)
2424 }
2525 }
26 bar := p.AddBar(int64(total), mpb.BarExtender(mpb.FillerFunc(efn)),
26 bar := p.AddBar(int64(total), mpb.BarExtender(mpb.BarFillerFunc(efn)),
2727 mpb.PrependDecorators(
2828 // simple name decorator
2929 decor.Name(name),
4444 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
4545 max := 100 * time.Millisecond
4646 for i := 0; i < total; i++ {
47 // start variable is solely for EWMA calculation
48 // EWMA's unit of measure is an iteration's taken time
4749 start := time.Now()
4850 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
49 // since ewma decorator is used, we need to pass time.Since(start)
50 bar.Increment(time.Since(start))
51 bar.Increment()
52 // since EWMA based decorator is used, DecoratorEwmaUpdate should be called
53 bar.DecoratorEwmaUpdate(time.Since(start))
5154 }
5255 }()
5356 }
00 module github.com/vbauerster/mpb/_examples/cancel
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v4"
10 "github.com/vbauerster/mpb/v4/decor"
9 "github.com/vbauerster/mpb/v5"
10 "github.com/vbauerster/mpb/v5/decor"
1111 )
1212
1313 func main() {
3838 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
3939 max := 100 * time.Millisecond
4040 for !bar.Completed() {
41 // start variable is solely for EWMA calculation
42 // EWMA's unit of measure is an iteration's taken time
4143 start := time.Now()
4244 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
43 // since ewma decorator is used, we need to pass time.Since(start)
44 bar.Increment(time.Since(start))
45 bar.Increment()
46 // since EWMA based decorator is used, DecoratorEwmaUpdate should be called
47 bar.DecoratorEwmaUpdate(time.Since(start))
4548 }
4649 }()
4750 }
00 module github.com/vbauerster/mpb/_examples/complex
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func init() {
4646 job := "\x1b[31;1;4minstalling\x1b[0m"
4747 // preparing delayed bars
4848 b := p.AddBar(rand.Int63n(101)+100,
49 mpb.BarParkTo(bars[i]),
50 mpb.BarClearOnComplete(),
49 mpb.BarQueueAfter(bars[i]),
50 mpb.BarFillerClearOnComplete(),
5151 mpb.PrependDecorators(
5252 decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
5353 decor.OnComplete(decor.Name(job, decor.WCSyncSpaceR), "done!"),
6666 p.Wait()
6767 }
6868
69 func newTask(wg *sync.WaitGroup, b *mpb.Bar, incrBy int) {
69 func newTask(wg *sync.WaitGroup, bar *mpb.Bar, incrBy int) {
7070 defer wg.Done()
7171 max := 100 * time.Millisecond
72 for !b.Completed() {
72 for !bar.Completed() {
73 // start variable is solely for EWMA calculation
74 // EWMA's unit of measure is an iteration's taken time
7375 start := time.Now()
7476 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
75 // since ewma decorator is used, we need to pass time.Since(start)
76 b.IncrBy(incrBy, time.Since(start))
77 bar.IncrBy(incrBy)
78 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
79 bar.DecoratorEwmaUpdate(time.Since(start))
7780 }
7881 }
00 module github.com/vbauerster/mpb/_examples/differentWidth
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
4444 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
4545 max := 100 * time.Millisecond
4646 for i := 0; i < total; i++ {
47 // start variable is solely for EWMA calculation
48 // EWMA's unit of measure is an iteration's taken time
4749 start := time.Now()
4850 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
49 // since ewma decorator is used, we need to pass time.Since(start)
50 bar.Increment(time.Since(start))
51 bar.Increment()
52 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
53 bar.DecoratorEwmaUpdate(time.Since(start))
5154 }
5255 }()
5356 }
00 module github.com/vbauerster/mpb/_examples/dynTotal
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
44 "math/rand"
55 "time"
66
7 "github.com/vbauerster/mpb/v4"
8 "github.com/vbauerster/mpb/v4/decor"
7 "github.com/vbauerster/mpb/v5"
8 "github.com/vbauerster/mpb/v5/decor"
99 )
1010
1111 func init() {
00 module github.com/vbauerster/mpb/_examples/io
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "io/ioutil"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
00 module github.com/vbauerster/mpb/_examples/merge
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
4646 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
4747 max := 100 * time.Millisecond
4848 for i := 0; i < total; i++ {
49 // start variable is solely for EWMA calculation
50 // EWMA's unit of measure is an iteration's taken time
4951 start := time.Now()
5052 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
51 // since ewma decorator is used, we need to pass time.Since(start)
52 bar.Increment(time.Since(start))
53 bar.Increment()
54 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
55 bar.DecoratorEwmaUpdate(time.Since(start))
5356 }
5457 }()
5558 }
00 module github.com/vbauerster/mpb/_examples/multiBars
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
3939 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
4040 max := 100 * time.Millisecond
4141 for i := 0; i < total; i++ {
42 // start variable is solely for EWMA calculation
43 // EWMA's unit of measure is an iteration's taken time
4244 start := time.Now()
4345 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
44 // since ewma decorator is used, we need to pass time.Since(start)
45 bar.Increment(time.Since(start))
46 bar.Increment()
47 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
48 bar.DecoratorEwmaUpdate(time.Since(start))
4649 }
4750 }()
4851 }
00 module github.com/vbauerster/mpb/_examples/panic
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
00 module github.com/vbauerster/mpb/_examples/poplog
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v4"
10 "github.com/vbauerster/mpb/v4/decor"
9 "github.com/vbauerster/mpb/v5"
10 "github.com/vbauerster/mpb/v5/decor"
1111 )
1212
1313 func main() {
3333 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
3434 max := 100 * time.Millisecond
3535 for i := 0; i < total; i++ {
36 // start variable is solely for EWMA calculation
37 // EWMA's unit of measure is an iteration's taken time
3638 start := time.Now()
3739 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
38 bar.Increment(time.Since(start))
40 bar.Increment()
41 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
42 bar.DecoratorEwmaUpdate(time.Since(start))
3943 }
4044 }()
4145 }
5761 p.Wait()
5862 }
5963
60 func makeLogBar(msg string) mpb.Filler {
64 func makeLogBar(msg string) mpb.BarFiller {
6165 limit := "%%.%ds"
62 return mpb.FillerFunc(func(w io.Writer, width int, st *decor.Statistics) {
66 return mpb.BarFillerFunc(func(w io.Writer, width int, st *decor.Statistics) {
6367 fmt.Fprintf(w, fmt.Sprintf(limit, width), msg)
6468 })
6569 }
00 module github.com/vbauerster/mpb/_examples/quietMode
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v4"
10 "github.com/vbauerster/mpb/v4/decor"
9 "github.com/vbauerster/mpb/v5"
10 "github.com/vbauerster/mpb/v5/decor"
1111 )
1212
1313 var quietMode bool
5757 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
5858 max := 100 * time.Millisecond
5959 for i := 0; i < total; i++ {
60 // start variable is solely for EWMA calculation
61 // EWMA's unit of measure is an iteration's taken time
6062 start := time.Now()
6163 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
62 // since ewma decorator is used, we need to pass time.Since(start)
63 bar.Increment(time.Since(start))
64 bar.Increment()
65 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
66 bar.DecoratorEwmaUpdate(time.Since(start))
6467 }
6568 }()
6669 }
00 module github.com/vbauerster/mpb/_examples/remove
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
1818
1919 for i := 0; i < numBars; i++ {
2020 name := fmt.Sprintf("Bar#%d:", i)
21 b := p.AddBar(int64(total), mpb.BarID(i),
21 bar := p.AddBar(int64(total),
22 mpb.BarID(i),
2223 mpb.BarOptOn(mpb.BarRemoveOnComplete(), func() bool { return i == 0 }),
2324 mpb.PrependDecorators(
2425 decor.Name(name),
3031 defer wg.Done()
3132 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
3233 max := 100 * time.Millisecond
33 for i := 0; !b.Completed(); i++ {
34 for i := 0; !bar.Completed(); i++ {
35 // start variable is solely for EWMA calculation
36 // EWMA's unit of measure is an iteration's taken time
3437 start := time.Now()
35 if b.ID() == 2 && i >= 42 {
38 if bar.ID() == 2 && i >= 42 {
3639 // aborting and removing while bar is running
37 b.Abort(true)
40 bar.Abort(true)
3841 }
3942 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
40 // since ewma decorator is used, we need to pass time.Since(start)
41 b.Increment(time.Since(start))
43 bar.Increment()
44 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
45 bar.DecoratorEwmaUpdate(time.Since(start))
4246 }
4347 }()
4448 }
00 module github.com/vbauerster/mpb/_examples/reverseBar
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
4141 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
4242 max := 100 * time.Millisecond
4343 for i := 0; i < total; i++ {
44 // start variable is solely for EWMA calculation
45 // EWMA's unit of measure is an iteration's taken time
4446 start := time.Now()
4547 time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
46 // since ewma decorator is used, we need to pass time.Since(start)
47 bar.Increment(time.Since(start))
48 bar.Increment()
49 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
50 bar.DecoratorEwmaUpdate(time.Since(start))
4851 }
4952 }()
5053 }
00 module github.com/vbauerster/mpb/_examples/singleBar
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
33 "math/rand"
44 "time"
55
6 "github.com/vbauerster/mpb/v4"
7 "github.com/vbauerster/mpb/v4/decor"
6 "github.com/vbauerster/mpb/v5"
7 "github.com/vbauerster/mpb/v5/decor"
88 )
99
1010 func main() {
3131 // simulating some work
3232 max := 100 * time.Millisecond
3333 for i := 0; i < total; i++ {
34 // start variable is solely for EWMA calculation
35 // EWMA's unit of measure is an iteration's taken time
3436 start := time.Now()
3537 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
36 // since ewma decorator is used, we need to pass time.Since(start)
37 bar.Increment(time.Since(start))
38 bar.Increment()
39 // we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
40 bar.DecoratorEwmaUpdate(time.Since(start))
3841 }
3942 // wait for our bar to complete and flush
4043 p.Wait()
00 module github.com/vbauerster/mpb/_examples/spinnerBar
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
00 module github.com/vbauerster/mpb/_examples/spinnerDecorator
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 func main() {
00 module github.com/vbauerster/mpb/_examples/stress
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v4"
9 "github.com/vbauerster/mpb/v4/decor"
8 "github.com/vbauerster/mpb/v5"
9 "github.com/vbauerster/mpb/v5/decor"
1010 )
1111
1212 const (
00 module github.com/vbauerster/mpb/_examples/suppressBar
11
2 go 1.13
2 go 1.14
33
4 require github.com/vbauerster/mpb/v4 v4.12.0
4 require github.com/vbauerster/mpb/v5 v5.0.0
77 "sync"
88 "time"
99
10 "github.com/vbauerster/mpb/v4"
11 "github.com/vbauerster/mpb/v4/decor"
10 "github.com/vbauerster/mpb/v5"
11 "github.com/vbauerster/mpb/v5/decor"
1212 )
1313
1414 func main() {
7575 ew.Unlock()
7676 }
7777
78 type customFiller struct {
79 mpb.Filler
80 base mpb.Filler
78 type myBarFiller struct {
79 mpb.BarFiller
80 base mpb.BarFiller
8181 }
8282
83 // implementing mpb.WrapFiller, so bar.SetRefill works
84 func (cf *customFiller) Base() mpb.Filler {
83 func (cf *myBarFiller) Base() mpb.BarFiller {
8584 return cf.base
8685 }
8786
88 func newCustomFiller(ch <-chan string, resume <-chan struct{}) (mpb.Filler, <-chan struct{}) {
87 func newCustomFiller(ch <-chan string, resume <-chan struct{}) (mpb.BarFiller, <-chan struct{}) {
8988 base := mpb.NewBarFiller(mpb.DefaultBarStyle, false)
9089 nextCh := make(chan struct{}, 1)
9190 var msg *string
92 filler := func(w io.Writer, width int, st *decor.Statistics) {
91 filler := mpb.BarFillerFunc(func(w io.Writer, width int, st *decor.Statistics) {
9392 select {
9493 case m := <-ch:
9594 defer func() {
107106 } else {
108107 base.Fill(w, width, st)
109108 }
110 }
111 cf := &customFiller{
112 Filler: mpb.FillerFunc(filler),
113 base: base,
109 })
110 cf := &myBarFiller{
111 BarFiller: filler,
112 base: base,
114113 }
115114 return cf, nextCh
116115 }