Codebase list golang-github-vbauerster-mpb / 40d8360
Syncable interface Vladimir Bauer 7 years ago
2 changed file(s) with 18 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
405405 columns := make([]chan int, 0, len(s.pDecorators)+len(s.aDecorators))
406406 var pCount int
407407 for _, d := range s.pDecorators {
408 if ok, ch := d.SyncWidth(); ok {
408 if ok, ch := d.Syncable(); ok {
409409 columns = append(columns, ch)
410410 pCount++
411411 }
412412 }
413413 var aCount int
414414 for _, d := range s.aDecorators {
415 if ok, ch := d.SyncWidth(); ok {
415 if ok, ch := d.Syncable(); ok {
416416 columns = append(columns, ch)
417417 aCount++
418418 }
4646 }
4747
4848 // Decorator interface.
49 // A decorator must implement this interface, in order to be used with mpb library.
4950 type Decorator interface {
5051 Decor(*Statistics) string
51 SyncWidth() (bool, chan int)
52 Syncable
53 }
54
55 // Syncable interface.
56 // All decorators implement this interface implicitly.
57 // Its Syncable method exposes width sync channel, if sync is enabled.
58 type Syncable interface {
59 Syncable() (bool, chan int)
5260 }
5361
5462 // OnCompleteMessenger interface.
5765 OnCompleteMessage(string)
5866 }
5967
68 // AmountReceiver interface.
69 // If decorator needs to receive increment amount,
70 // so this is the right interface to implement.
6071 type AmountReceiver interface {
6172 NextAmount(int, ...time.Duration)
6273 }
6374
6475 // ShutdownListener interface.
65 // If decorator implements this interface, its Shutdown method
66 // will be called once on bar shutdown event.
76 // If decorator needs to be notified once upon bar shutdown event,
77 // so this is the right interface to implement.
6778 type ShutdownListener interface {
6879 Shutdown()
6980 }
114125 }
115126 }
116127
117 func (wc *WC) SyncWidth() (bool, chan int) {
128 func (wc *WC) Syncable() (bool, chan int) {
118129 return (wc.C & DSyncWidth) != 0, wc.wsync
119130 }
120131
131142 return decorator
132143 }
133144
145 // completeMsg for internal usage.
134146 type completeMsg struct {
135147 msg string
136148 }