Refactoring: satrtBlock to sbEta
Vladimir Bauer
8 years ago
| 38 | 38 | |
| 39 | 39 | total := 100 |
| 40 | 40 | name := "Single Bar:" |
| 41 | startBlock := make(chan time.Time) | |
| 41 | sbEta := make(chan time.Time) | |
| 42 | 42 | // adding a single bar |
| 43 | 43 | bar := p.AddBar(int64(total), |
| 44 | 44 | mpb.PrependDecorators( |
| 47 | 47 | // replace ETA decorator with "done" message, OnComplete event |
| 48 | 48 | decor.OnComplete( |
| 49 | 49 | // ETA decorator with default eta age, and width reservation of 4 |
| 50 | decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 4}), "done", | |
| 50 | decor.ETA(decor.ET_STYLE_GO, 0, sbEta, decor.WC{W: 4}), "done", | |
| 51 | 51 | ), |
| 52 | 52 | ), |
| 53 | 53 | mpb.AppendDecorators(decor.Percentage()), |
| 57 | 57 | max := 100 * time.Millisecond |
| 58 | 58 | for i := 0; i < total; i++ { |
| 59 | 59 | // update start block time, required for ETA calculation |
| 60 | startBlock <- time.Now() | |
| 60 | sbEta <- time.Now() | |
| 61 | 61 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 62 | 62 | // increment by 1 (there is bar.IncrBy(int) method, if needed) |
| 63 | 63 | bar.Increment() |
| 75 | 75 | |
| 76 | 76 | for i := 0; i < numBars; i++ { |
| 77 | 77 | name := fmt.Sprintf("Bar#%d:", i) |
| 78 | startBlock := make(chan time.Time) | |
| 78 | sbEta := make(chan time.Time) | |
| 79 | 79 | bar := p.AddBar(int64(total), |
| 80 | 80 | mpb.PrependDecorators( |
| 81 | 81 | // display our name with one space on the right |
| 87 | 87 | // replace ETA decorator with "done" message, OnComplete event |
| 88 | 88 | decor.OnComplete( |
| 89 | 89 | // ETA decorator with default eta age, and width reservation of 3 |
| 90 | decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 3}), "done", | |
| 90 | decor.ETA(decor.ET_STYLE_GO, 0, sbEta, decor.WC{W: 3}), "done", | |
| 91 | 91 | ), |
| 92 | 92 | ), |
| 93 | 93 | ) |
| 96 | 96 | defer wg.Done() |
| 97 | 97 | max := 100 * time.Millisecond |
| 98 | 98 | for i := 0; i < total; i++ { |
| 99 | startBlock <- time.Now() | |
| 99 | sbEta <- time.Now() | |
| 100 | 100 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 101 | 101 | bar.Increment() |
| 102 | 102 | } |
| 21 | 21 | |
| 22 | 22 | for i := 0; i < numBars; i++ { |
| 23 | 23 | name := fmt.Sprintf("Bar#%d:", i) |
| 24 | startBlock := make(chan time.Time) | |
| 24 | sbEta := make(chan time.Time) | |
| 25 | 25 | bar := p.AddBar(int64(total), |
| 26 | 26 | mpb.PrependDecorators( |
| 27 | 27 | // display our name with one space on the right |
| 33 | 33 | // replace ETA decorator with "done" message, OnComplete event |
| 34 | 34 | decor.OnComplete( |
| 35 | 35 | // ETA decorator with default eta age, and width reservation of 3 |
| 36 | decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 3}), "done", | |
| 36 | decor.ETA(decor.ET_STYLE_GO, 0, sbEta, decor.WC{W: 3}), "done", | |
| 37 | 37 | ), |
| 38 | 38 | ), |
| 39 | 39 | ) |
| 42 | 42 | defer wg.Done() |
| 43 | 43 | max := 100 * time.Millisecond |
| 44 | 44 | for i := 0; i < total; i++ { |
| 45 | startBlock <- time.Now() | |
| 45 | sbEta <- time.Now() | |
| 46 | 46 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 47 | 47 | bar.Increment() |
| 48 | 48 | } |
| 19 | 19 | |
| 20 | 20 | total := 100 |
| 21 | 21 | name := "Single Bar:" |
| 22 | startBlock := make(chan time.Time) | |
| 22 | sbEta := make(chan time.Time) | |
| 23 | 23 | // adding a single bar |
| 24 | 24 | bar := p.AddBar(int64(total), |
| 25 | 25 | mpb.PrependDecorators( |
| 28 | 28 | // replace ETA decorator with "done" message, OnComplete event |
| 29 | 29 | decor.OnComplete( |
| 30 | 30 | // ETA decorator with default eta age, and width reservation of 4 |
| 31 | decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 4}), "done", | |
| 31 | decor.ETA(decor.ET_STYLE_GO, 0, sbEta, decor.WC{W: 4}), "done", | |
| 32 | 32 | ), |
| 33 | 33 | ), |
| 34 | 34 | mpb.AppendDecorators(decor.Percentage()), |
| 38 | 38 | max := 100 * time.Millisecond |
| 39 | 39 | for i := 0; i < total; i++ { |
| 40 | 40 | // update start block time, required for ETA calculation |
| 41 | startBlock <- time.Now() | |
| 41 | sbEta <- time.Now() | |
| 42 | 42 | time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) |
| 43 | 43 | // increment by 1 (there is bar.IncrBy(int) method, if needed) |
| 44 | 44 | bar.Increment() |