Codebase list golang-github-vbauerster-mpb / 83a2bb9
TraverseDecorators from withing p.serve loop Remedy possible data race. Vladimir Bauer 1 year, 10 months ago
1 changed file(s) with 14 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
147147 if filler == nil {
148148 filler = NopStyle().Build()
149149 }
150 type result struct {
151 bar *Bar
152 bs *bState
153 }
154 ch := make(chan result)
150 ch := make(chan *Bar)
155151 select {
156152 case p.operateState <- func(ps *pState) {
157153 bs := ps.makeBarState(total, filler, options...)
158154 bar := newBar(ps.ctx, p, bs)
155 bar.TraverseDecorators(func(d decor.Decorator) {
156 if d, ok := d.(decor.AverageDecorator); ok {
157 bs.averageDecorators = append(bs.averageDecorators, d)
158 }
159 if d, ok := d.(decor.EwmaDecorator); ok {
160 bs.ewmaDecorators = append(bs.ewmaDecorators, d)
161 }
162 if d, ok := d.(decor.ShutdownListener); ok {
163 bs.shutdownListeners = append(bs.shutdownListeners, d)
164 }
165 })
159166 if bs.waitBar != nil {
160167 ps.queueBars[bs.waitBar] = bar
161168 } else {
162169 ps.hm.push(bar, true)
163170 }
164171 ps.idCount++
165 ch <- result{bar, bs}
172 ch <- bar
166173 }:
167 res := <-ch
168 bar, bs := res.bar, res.bs
169 bar.TraverseDecorators(func(d decor.Decorator) {
170 if d, ok := d.(decor.AverageDecorator); ok {
171 bs.averageDecorators = append(bs.averageDecorators, d)
172 }
173 if d, ok := d.(decor.EwmaDecorator); ok {
174 bs.ewmaDecorators = append(bs.ewmaDecorators, d)
175 }
176 if d, ok := d.(decor.ShutdownListener); ok {
177 bs.shutdownListeners = append(bs.shutdownListeners, d)
178 }
179 })
180 return bar, nil
174 return <-ch, nil
181175 case <-p.done:
182176 return nil, DoneError
183177 }