Codebase list golang-github-vbauerster-mpb / d7cad44
Synchronizer and comma ok Vladimir Bauer 7 years ago
3 changed file(s) with 12 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
365365 columns := make([]chan int, 0, len(s.pDecorators)+len(s.aDecorators))
366366 var pCount int
367367 for _, d := range s.pDecorators {
368 if ok, ch := d.Syncable(); ok {
368 if ch, ok := d.Sync(); ok {
369369 columns = append(columns, ch)
370370 pCount++
371371 }
372372 }
373373 var aCount int
374374 for _, d := range s.aDecorators {
375 if ok, ch := d.Syncable(); ok {
375 if ch, ok := d.Sync(); ok {
376376 columns = append(columns, ch)
377377 aCount++
378378 }
5454 // A decorator must implement this interface, in order to be used with
5555 // mpb library.
5656 type Decorator interface {
57 Synchronizer
5758 Decor(*Statistics) string
58 Syncable
5959 }
6060
61 // Syncable interface.
62 // All decorators implement this interface implicitly. Its Syncable
61 // Synchronizer interface.
62 // All decorators implement this interface implicitly. Its Sync
6363 // method exposes width sync channel, if sync is enabled.
64 type Syncable interface {
65 Syncable() (bool, chan int)
64 type Synchronizer interface {
65 Sync() (chan int, bool)
6666 }
6767
6868 // OnCompleteMessenger interface.
9696
9797 // WC is a struct with two public fields W and C, both of int type.
9898 // W represents width and C represents bit set of width related config.
99 // A decorator should embed WC, in order to become Syncable.
99 // A decorator should embed WC, to enable width synchronization.
100100 type WC struct {
101101 W int
102102 C int
133133 }
134134 }
135135
136 // Syncable is implementation of Syncable interface.
137 func (wc *WC) Syncable() (bool, chan int) {
138 return (wc.C & DSyncWidth) != 0, wc.wsync
136 // Sync is implementation of Synchronizer interface.
137 func (wc *WC) Sync() (chan int, bool) {
138 return wc.wsync, (wc.C & DSyncWidth) != 0
139139 }
140140
141141 // OnComplete returns decorator, which wraps provided decorator, with
210210 func toSyncMatrix(ss []step) map[int][]chan int {
211211 var column []chan int
212212 for _, s := range ss {
213 if ok, ch := s.decorator.Syncable(); ok {
213 if ch, ok := s.decorator.Sync(); ok {
214214 column = append(column, ch)
215215 }
216216 }