Codebase list golang-github-vbauerster-mpb / 3f13667
non blocking subscribeDecorators Vladimir Bauer 5 years ago
1 changed file(s) with 10 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
138138
139139 // TraverseDecorators traverses all available decorators and calls cb func on each.
140140 func (b *Bar) TraverseDecorators(cb func(decor.Decorator)) {
141 b.operateState <- func(s *bState) {
141 select {
142 case b.operateState <- func(s *bState) {
142143 for _, decorators := range [...][]decor.Decorator{
143144 s.pDecorators,
144145 s.aDecorators,
147148 cb(extractBaseDecorator(d))
148149 }
149150 }
151 }:
152 case <-b.done:
150153 }
151154 }
152155
349352 shutdownListeners = append(shutdownListeners, d)
350353 }
351354 })
352 b.operateState <- func(s *bState) {
355 select {
356 case b.operateState <- func(s *bState) {
353357 s.averageDecorators = averageDecorators
354358 s.ewmaDecorators = ewmaDecorators
355359 s.shutdownListeners = shutdownListeners
356 }
357 b.hasEwmaDecorators = len(ewmaDecorators) != 0
360 }:
361 b.hasEwmaDecorators = len(ewmaDecorators) != 0
362 case <-b.done:
363 }
358364 }
359365
360366 func (b *Bar) refreshTillShutdown() {