Codebase list golang-github-vbauerster-mpb / d3c2896
correct decorator wrapper for suppressBar example Vladimir Bauer 2 years ago
1 changed file(s) with 17 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
100100 ew.Unlock()
101101 }
102102
103 type percentage struct {
104 decor.Decorator
105 suspend <-chan struct{}
106 }
107
108 func (d percentage) Decor(s decor.Statistics) (string, int) {
109 select {
110 case <-d.suspend:
111 return d.Format("")
112 default:
113 return d.Decorator.Decor(s)
114 }
115 }
116
103117 func newCustomPercentage(nextCh <-chan struct{}) decor.Decorator {
104 base := decor.Percentage()
105 fn := func(s decor.Statistics) string {
106 select {
107 case <-nextCh:
108 return ""
109 default:
110 return base.Decor(s)
111 }
118 return percentage{
119 Decorator: decor.Percentage(),
120 suspend: nextCh,
112121 }
113 return decor.Any(fn)
114122 }