Codebase list golang-github-vbauerster-mpb / db1abd2
refactoring panic example Vladimir Bauer 6 years ago
1 changed file(s) with 4 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
22 import (
33 "fmt"
44 "os"
5 "strings"
56 "sync"
67 "time"
78
1314 var wg sync.WaitGroup
1415 p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithDebugOutput(os.Stderr))
1516
16 wantPanic := "Some really long panic panic panic panic panic panic panic, really it is very long"
17 wantPanic := strings.Repeat("Panic ", 64)
1718 numBars := 3
1819 wg.Add(numBars)
1920
3435 }
3536
3637 func panicDecorator(name, panicMsg string) decor.Decorator {
37 return decor.Any(func(s decor.Statistics) string {
38 if s.ID == 1 && s.Current >= 42 {
38 return decor.Any(func(st decor.Statistics) string {
39 if st.ID == 1 && st.Current >= 42 {
3940 panic(panicMsg)
4041 }
4142 return name