Skip to content

Commit b4bd98c

Browse files
committed
bar EwmaIncr: no need for sync.WaitGroup
1 parent 8c0512d commit b4bd98c

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

bar.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"io"
77
"strings"
8-
"sync"
98
"time"
109

1110
"github.com/acarl005/stripansi"
@@ -266,21 +265,14 @@ func (b *Bar) EwmaIncrBy(n int, iterDur time.Duration) {
266265
func (b *Bar) EwmaIncrInt64(n int64, iterDur time.Duration) {
267266
select {
268267
case b.operateState <- func(s *bState) {
269-
var wg sync.WaitGroup
270-
wg.Add(len(s.ewmaDecorators))
271268
for _, d := range s.ewmaDecorators {
272-
// d := d // NOTE: uncomment for Go < 1.22, see /doc/faq#closures_and_goroutines
273-
go func() {
274-
defer wg.Done()
275-
d.EwmaUpdate(n, iterDur)
276-
}()
269+
d.EwmaUpdate(n, iterDur)
277270
}
278271
s.current += n
279272
if s.triggerComplete && s.current >= s.total {
280273
s.current = s.total
281274
s.triggerCompletion(b)
282275
}
283-
wg.Wait()
284276
}:
285277
case <-b.ctx.Done():
286278
}
@@ -295,21 +287,14 @@ func (b *Bar) EwmaSetCurrent(current int64, iterDur time.Duration) {
295287
select {
296288
case b.operateState <- func(s *bState) {
297289
n := current - s.current
298-
var wg sync.WaitGroup
299-
wg.Add(len(s.ewmaDecorators))
300290
for _, d := range s.ewmaDecorators {
301-
// d := d // NOTE: uncomment for Go < 1.22, see /doc/faq#closures_and_goroutines
302-
go func() {
303-
defer wg.Done()
304-
d.EwmaUpdate(n, iterDur)
305-
}()
291+
d.EwmaUpdate(n, iterDur)
306292
}
307293
s.current = current
308294
if s.triggerComplete && s.current >= s.total {
309295
s.current = s.total
310296
s.triggerCompletion(b)
311297
}
312-
wg.Wait()
313298
}:
314299
case <-b.ctx.Done():
315300
}

0 commit comments

Comments
 (0)