Codebase list golang-github-vbauerster-mpb / 976cad7
revise dynamic total example Vladimir Bauer 7 years ago
1 changed file(s) with 8 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2626 for {
2727 n, err := read()
2828 total += int64(n)
29 time.Sleep(time.Duration(rand.Intn(10)+1) * maxSleep / 10)
30 bar.IncrBy(n)
3129 if err == io.EOF {
32 // total is known, final=true
33 bar.SetTotal(total, true)
3430 break
3531 }
36 // total is unknown, final=false
32 // while total is unknown,
33 // set it to a positive number which is greater than current total,
34 // to make sure no complete event is triggered by next IncrBy call.
3735 bar.SetTotal(total+2048, false)
36 bar.IncrBy(n)
37 time.Sleep(time.Duration(rand.Intn(10)+1) * maxSleep / 10)
3838 }
39
40 // force bar complete event, note true flag
41 bar.SetTotal(total, true)
3942
4043 p.Wait()
4144 }