some refactoring
Vladimir Bauer
5 years ago
| 37 | 37 |
wantID := 11
|
| 38 | 38 |
bar := p.AddBar(int64(total), BarID(wantID))
|
| 39 | 39 |
|
| 40 | |
go func(total int) {
|
|
40 |
go func() {
|
| 41 | 41 |
for i := 0; i < total; i++ {
|
| 42 | 42 |
time.Sleep(50 * time.Millisecond)
|
| 43 | 43 |
bar.Increment()
|
| 44 | 44 |
}
|
| 45 | |
}(total)
|
|
45 |
}()
|
| 46 | 46 |
|
| 47 | 47 |
gotID := bar.ID()
|
| 48 | 48 |
if gotID != wantID {
|
| 3 | 3 |
"sync"
|
| 4 | 4 |
"testing"
|
| 5 | 5 |
|
| 6 | |
. "github.com/vbauerster/mpb/v5"
|
|
6 |
"github.com/vbauerster/mpb/v5"
|
| 7 | 7 |
"github.com/vbauerster/mpb/v5/decor"
|
| 8 | 8 |
)
|
| 9 | 9 |
|
|
| 181 | 181 |
t.Fail()
|
| 182 | 182 |
}
|
| 183 | 183 |
|
| 184 | |
numBars := len(testCases[0])
|
| 185 | |
var wg sync.WaitGroup
|
| 186 | 184 |
for _, columnCase := range testCases {
|
|
185 |
mpb.SyncWidth(toSyncMatrix(columnCase))
|
|
186 |
numBars := len(columnCase)
|
|
187 |
gott := make([]chan string, numBars)
|
|
188 |
wg := new(sync.WaitGroup)
|
| 187 | 189 |
wg.Add(numBars)
|
| 188 | |
SyncWidth(toSyncMatrix(columnCase))
|
| 189 | |
gott := make([]chan string, numBars)
|
| 190 | |
for i := 0; i < numBars; i++ {
|
| 191 | |
gott[i] = make(chan string, 1)
|
| 192 | |
go func(s step, ch chan string) {
|
|
190 |
for i, step := range columnCase {
|
|
191 |
step := step
|
|
192 |
ch := make(chan string, 1)
|
|
193 |
go func() {
|
| 193 | 194 |
defer wg.Done()
|
| 194 | |
ch <- s.decorator.Decor(s.stat)
|
| 195 | |
}(columnCase[i], gott[i])
|
|
195 |
ch <- step.decorator.Decor(step.stat)
|
|
196 |
}()
|
|
197 |
gott[i] = ch
|
| 196 | 198 |
}
|
| 197 | 199 |
wg.Wait()
|
| 198 | 200 |
|