startBlock to sbEta
Vladimir Bauer
8 years ago
| 22 | 22 | |
| 23 | 23 | total := 100 |
| 24 | 24 | name := "Single Bar:" |
| 25 | startBlock := make(chan time.Time) | |
| 25 | sbEta := make(chan time.Time) | |
| 26 | 26 | // adding a single bar |
| 27 | 27 | bar := p.AddBar(int64(total), |
| 28 | 28 | mpb.PrependDecorators( |
| 31 | 31 | // replace ETA decorator with "done" message, OnComplete event |
| 32 | 32 | decor.OnComplete( |
| 33 | 33 | // ETA decorator with default eta age, and width reservation of 4 |
| 34 | decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 4}), "done", | |
| 34 | decor.ETA(decor.ET_STYLE_GO, 0, sbEta, decor.WC{W: 4}), "done", | |
| 35 | 35 | ), |
| 36 | 36 | ), |
| 37 | 37 | mpb.AppendDecorators(decor.Percentage()), |
| 41 | 41 | max := 100 * time.Millisecond |
| 42 | 42 | for i := 0; i < total; i++ { |
| 43 | 43 | // update start block time, required for ETA calculation |
| 44 | startBlock <- time.Now() | |
| 44 | sbEta <- time.Now() | |
| 45 | 45 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 46 | 46 | // increment by 1 (there is bar.IncrBy(int) method, if needed) |
| 47 | 47 | bar.Increment() |