diff --git a/bar.go b/bar.go index ce3d989..6c30292 100644 --- a/bar.go +++ b/bar.go @@ -139,7 +139,8 @@ // TraverseDecorators traverses all available decorators and calls cb func on each. func (b *Bar) TraverseDecorators(cb func(decor.Decorator)) { - b.operateState <- func(s *bState) { + select { + case b.operateState <- func(s *bState) { for _, decorators := range [...][]decor.Decorator{ s.pDecorators, s.aDecorators, @@ -148,6 +149,8 @@ cb(extractBaseDecorator(d)) } } + }: + case <-b.done: } } @@ -350,12 +353,15 @@ shutdownListeners = append(shutdownListeners, d) } }) - b.operateState <- func(s *bState) { + select { + case b.operateState <- func(s *bState) { s.averageDecorators = averageDecorators s.ewmaDecorators = ewmaDecorators s.shutdownListeners = shutdownListeners - } - b.hasEwmaDecorators = len(ewmaDecorators) != 0 + }: + b.hasEwmaDecorators = len(ewmaDecorators) != 0 + case <-b.done: + } } func (b *Bar) refreshTillShutdown() {