non blocking subscribeDecorators
Vladimir Bauer
5 years ago
| 138 | 138 | |
| 139 | 139 | // TraverseDecorators traverses all available decorators and calls cb func on each. |
| 140 | 140 | func (b *Bar) TraverseDecorators(cb func(decor.Decorator)) { |
| 141 | b.operateState <- func(s *bState) { | |
| 141 | select { | |
| 142 | case b.operateState <- func(s *bState) { | |
| 142 | 143 | for _, decorators := range [...][]decor.Decorator{ |
| 143 | 144 | s.pDecorators, |
| 144 | 145 | s.aDecorators, |
| 147 | 148 | cb(extractBaseDecorator(d)) |
| 148 | 149 | } |
| 149 | 150 | } |
| 151 | }: | |
| 152 | case <-b.done: | |
| 150 | 153 | } |
| 151 | 154 | } |
| 152 | 155 | |
| 349 | 352 | shutdownListeners = append(shutdownListeners, d) |
| 350 | 353 | } |
| 351 | 354 | }) |
| 352 | b.operateState <- func(s *bState) { | |
| 355 | select { | |
| 356 | case b.operateState <- func(s *bState) { | |
| 353 | 357 | s.averageDecorators = averageDecorators |
| 354 | 358 | s.ewmaDecorators = ewmaDecorators |
| 355 | 359 | s.shutdownListeners = shutdownListeners |
| 356 | } | |
| 357 | b.hasEwmaDecorators = len(ewmaDecorators) != 0 | |
| 360 | }: | |
| 361 | b.hasEwmaDecorators = len(ewmaDecorators) != 0 | |
| 362 | case <-b.done: | |
| 363 | } | |
| 358 | 364 | } |
| 359 | 365 | |
| 360 | 366 | func (b *Bar) refreshTillShutdown() { |