correct decorator wrapper for suppressBar example
Vladimir Bauer
2 years ago
| 100 | 100 | ew.Unlock() |
| 101 | 101 | } |
| 102 | 102 | |
| 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 | ||
| 103 | 117 | 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, | |
| 112 | 121 | } |
| 113 | return decor.Any(fn) | |
| 114 | 122 | } |