refactoring panic example
Vladimir Bauer
6 years ago
| 2 | 2 | import ( |
| 3 | 3 | "fmt" |
| 4 | 4 | "os" |
| 5 | "strings" | |
| 5 | 6 | "sync" |
| 6 | 7 | "time" |
| 7 | 8 | |
| 13 | 14 | var wg sync.WaitGroup |
| 14 | 15 | p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithDebugOutput(os.Stderr)) |
| 15 | 16 | |
| 16 | wantPanic := "Some really long panic panic panic panic panic panic panic, really it is very long" | |
| 17 | wantPanic := strings.Repeat("Panic ", 64) | |
| 17 | 18 | numBars := 3 |
| 18 | 19 | wg.Add(numBars) |
| 19 | 20 | |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | 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 { | |
| 39 | 40 | panic(panicMsg) |
| 40 | 41 | } |
| 41 | 42 | return name |