Skip to content

Commit 8609301

Browse files
committed
refactor: examples update to use p.New()
1 parent 9843691 commit 8609301

File tree

12 files changed

+26
-28
lines changed

12 files changed

+26
-28
lines changed

example/cancel/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func main() {
1919
var wg sync.WaitGroup
2020
ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
2121
defer cancel()
22-
p := mpb.New(ctx).SetWidth(64)
22+
p := mpb.New().SetWidth(64).WithContext(ctx)
2323

2424
name1 := "Bar#1:"
2525
bar1 := p.AddBar(50).

example/io/multiple/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func main() {
1919
url2 := "https://homebrew.bintray.com/bottles/libtiff-4.0.7.sierra.bottle.tar.gz"
2020

2121
var wg sync.WaitGroup
22-
p := mpb.New(nil).SetWidth(60)
22+
p := mpb.New().SetWidth(60)
2323

2424
for i, url := range [...]string{url1, url2} {
2525
wg.Add(1)

example/io/single/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
}
3636
defer dest.Close()
3737

38-
p := mpb.New(nil).SetWidth(64)
38+
p := mpb.New().SetWidth(64)
3939

4040
bar := p.AddBar(size).
4141
PrependCounters("%3s / %3s", mpb.UnitBytes, 18, 0).

example/prependETA/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const (
1616
func main() {
1717

1818
var wg sync.WaitGroup
19-
p := mpb.New(nil).SetWidth(64)
20-
// p := mpb.New(nil).RefreshRate(80 * time.Millisecond).SetWidth(64)
19+
p := mpb.New().SetWidth(64)
2120

2221
name1 := "Bar#1:"
2322
bar1 := p.AddBar(50).

example/prependElapsed/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const (
1616
func main() {
1717

1818
var wg sync.WaitGroup
19-
p := mpb.New(nil).SetWidth(64)
20-
// p := mpb.New(nil).RefreshRate(80 * time.Millisecond).SetWidth(64)
19+
p := mpb.New().SetWidth(64)
2120

2221
name1 := "Bar#1:"
2322
bar1 := p.AddBar(50).

example/remove/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ const (
1616
func main() {
1717

1818
var wg sync.WaitGroup
19-
p := mpb.New(nil).SetWidth(64)
20-
// p := mpb.New(nil).RefreshRate(100 * time.Millisecond).SetWidth(64)
19+
p := mpb.New().SetWidth(64)
2120

2221
name1 := "Bar#1:"
2322
bar1 := p.AddBar(50).

example/simple/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func main() {
1313
var wg sync.WaitGroup
14-
p := mpb.New(nil)
14+
p := mpb.New()
1515
wg.Add(3) // add wg delta
1616
for i := 0; i < 3; i++ {
1717
name := fmt.Sprintf("Bar#%d:", i)
@@ -31,6 +31,4 @@ func main() {
3131
}
3232
wg.Wait() // Wait for goroutines to finish
3333
p.Stop() // Stop mpb's rendering goroutine
34-
// p.AddBar(1) // panic: you cannot reuse p, create new one!
35-
fmt.Println("finish")
3634
}

example/singleBar/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import (
99

1010
func main() {
1111
// Star mpb's rendering goroutine.
12-
// If you don't plan to cancel, feed with nil
13-
// otherwise provide context.Context, see cancel example
14-
p := mpb.New(nil)
15-
// Set custom width for every bar, which mpb will contain
12+
p := mpb.New()
13+
// Set custom width for every bar, which mpb will render
1614
// The default one in 70
1715
p.SetWidth(80)
1816
// Set custom format for every bar, the default one is "[=>-]"

example/sort/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func percentage(total, current int64, ratio int) int {
4444
func main() {
4545

4646
var wg sync.WaitGroup
47-
p := mpb.New(nil).SetWidth(60).BeforeRenderFunc(sortByProgressFunc())
47+
p := mpb.New().SetWidth(60).BeforeRenderFunc(sortByProgressFunc())
4848

4949
name1 := "Bar#1:"
5050
bar1 := p.AddBar(100).

example/stress/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
func main() {
1818

1919
var wg sync.WaitGroup
20-
p := mpb.New(nil)
20+
p := mpb.New()
2121
wg.Add(totalBars)
2222

2323
for i := 0; i < totalBars; i++ {

0 commit comments

Comments
 (0)