quietMode example with io.Discard
Vladimir Bauer
3 years ago
| 2 | 2 | import ( |
| 3 | 3 | "flag" |
| 4 | 4 | "fmt" |
| 5 | "io" | |
| 5 | 6 | "math/rand" |
| 6 | 7 | "sync" |
| 7 | 8 | "time" |
| 22 | 23 | // passed wg will be accounted at p.Wait() call |
| 23 | 24 | p := mpb.New( |
| 24 | 25 | mpb.WithWaitGroup(&wg), |
| 25 | mpb.ContainerOptional( | |
| 26 | // setting to nil will: | |
| 27 | // set output to ioutil.Discard and disable refresh rate cycle, in | |
| 28 | // order not to consume much CPU. Hovewer a single refresh still will | |
| 29 | // be triggered on bar complete event, per each bar. | |
| 30 | mpb.WithOutput(nil), | |
| 31 | quietMode, | |
| 32 | ), | |
| 26 | mpb.ContainerOptional(mpb.WithOutput(io.Discard), quietMode), | |
| 33 | 27 | ) |
| 34 | 28 | total, numBars := 100, 3 |
| 35 | 29 | wg.Add(numBars) |