Codebase list golang-github-vbauerster-mpb / 3ac6abb
Examples refactoring: startBlock to sbEta Vladimir Bauer 8 years ago
6 changed file(s) with 22 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
3131
3232 for i := 0; i < numBars; i++ {
3333 name := fmt.Sprintf("Bar#%d:", i)
34 startBlock := make(chan time.Time)
34 sbEta := make(chan time.Time)
3535 bar := p.AddBar(int64(total),
3636 mpb.PrependDecorators(
3737 decor.Name(name),
38 decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WCSyncSpace),
38 decor.ETA(decor.ET_STYLE_GO, 60, sbEta, decor.WCSyncSpace),
3939 ),
4040 mpb.AppendDecorators(
4141 decor.Percentage(decor.WC{W: 5}),
4646 defer wg.Done()
4747 max := 100 * time.Millisecond
4848 for !bar.Completed() {
49 startBlock <- time.Now()
49 sbEta <- time.Now()
5050 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
5151 bar.Increment()
5252 }
4343 doneWg.Add(1)
4444 i := i
4545 go func() {
46 startBlock := make(chan time.Time)
46 sbEta := make(chan time.Time)
4747 task := fmt.Sprintf("Task#%02d:", i)
4848 job := "installing"
4949 // preparing delayed bars
5353 mpb.PrependDecorators(
5454 decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
5555 decor.OnComplete(decor.Name(job, decor.WCSyncSpaceR), "done!", decor.WCSyncSpaceR),
56 decor.OnComplete(decor.ETA(decor.ET_STYLE_MMSS, 60, startBlock, decor.WCSyncWidth), "", decor.WCSyncSpace),
56 decor.OnComplete(decor.ETA(decor.ET_STYLE_MMSS, 60, sbEta, decor.WCSyncWidth), "", decor.WCSyncSpace),
5757 ),
5858 mpb.AppendDecorators(
5959 decor.OnComplete(decor.Percentage(decor.WC{W: 5}), ""),
6161 )
6262 // waiting for download to complete, before starting install job
6363 downloadWgg[i].Wait()
64 go newTask(doneWg, b, numBars-i, startBlock)
64 go newTask(doneWg, b, numBars-i, sbEta)
6565 }()
6666 }
6767
6868 p.Wait()
6969 }
7070
71 func newTask(wg *sync.WaitGroup, b *mpb.Bar, incrBy int, startBlock chan<- time.Time) {
71 func newTask(wg *sync.WaitGroup, b *mpb.Bar, incrBy int, sbCh chan<- time.Time) {
7272 defer wg.Done()
7373 max := 100 * time.Millisecond
7474 for !b.Completed() {
75 if startBlock != nil {
76 startBlock <- time.Now()
75 if sbCh != nil {
76 sbCh <- time.Now()
7777 }
7878 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
7979 b.IncrBy(incrBy)
2525 if i != 1 {
2626 name = fmt.Sprintf("Bar#%d:", i)
2727 }
28 startBlock := make(chan time.Time)
28 sbEta := make(chan time.Time)
2929 b := p.AddBar(int64(total),
3030 mpb.PrependDecorators(
3131 decor.Name(name, decor.WCSyncWidth),
3232 decor.OnComplete(
33 decor.ETA(decor.ET_STYLE_MMSS, 60, startBlock, decor.WC{W: 6}),
33 decor.ETA(decor.ET_STYLE_MMSS, 60, sbEta, decor.WC{W: 6}),
3434 "Done",
3535 decor.WCSyncSpace,
3636 ),
4343 defer wg.Done()
4444 max := 100 * time.Millisecond
4545 for i := 0; i < total; i++ {
46 startBlock <- time.Now()
46 sbEta <- time.Now()
4747 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4848 b.Increment()
4949 }
2828 bOption = mpb.BarRemoveOnComplete()
2929 }
3030
31 startBlock := make(chan time.Time)
31 sbEta := make(chan time.Time)
3232 b := p.AddBar(int64(total), mpb.BarID(i),
3333 bOption,
3434 mpb.PrependDecorators(
3535 decor.Name(name),
36 decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WCSyncSpace),
36 decor.ETA(decor.ET_STYLE_GO, 60, sbEta, decor.WCSyncSpace),
3737 ),
38 mpb.AppendDecorators(
39 decor.Percentage(),
40 ),
38 mpb.AppendDecorators(decor.Percentage()),
4139 )
4240 go func() {
4341 defer wg.Done()
4442 max := 100 * time.Millisecond
4543 for i := 0; i < total; i++ {
46 startBlock <- time.Now()
44 sbEta <- time.Now()
4745 if b.ID() == 2 && i == 42 {
4846 p.Abort(b)
4947 return
2525 if i != 1 {
2626 name = fmt.Sprintf("Bar#%d:", i)
2727 }
28 startBlock := make(chan time.Time)
28 sbEta := make(chan time.Time)
2929 b := p.AddBar(int64(total),
3030 mpb.PrependDecorators(
3131 decor.Name(name, decor.WCSyncWidth),
3232 decor.CountersNoUnit("%d / %d", decor.WCSyncSpace),
3333 ),
3434 mpb.AppendDecorators(
35 decor.ETA(decor.ET_STYLE_GO, 0, startBlock, decor.WC{W: 3}),
35 decor.ETA(decor.ET_STYLE_GO, 60, sbEta, decor.WC{W: 3}),
3636 ),
3737 )
3838 go func() {
3939 defer wg.Done()
4040 max := 100 * time.Millisecond
4141 for i := 0; i < total; i++ {
42 startBlock <- time.Now()
42 sbEta <- time.Now()
4343 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4444 if i&1 == 1 {
4545 priority := total - int(b.Current())
2626 for i := 0; i < totalBars; i++ {
2727 name := fmt.Sprintf("Bar#%02d: ", i)
2828 total := rand.Intn(320) + 10
29 startBlock := make(chan time.Time)
29 sbEta := make(chan time.Time)
3030 bar := p.AddBar(int64(total),
3131 mpb.PrependDecorators(
3232 decor.Name(name),
33 decor.ETA(decor.ET_STYLE_GO, 60, startBlock, decor.WCSyncSpace),
33 decor.ETA(decor.ET_STYLE_GO, 60, sbEta, decor.WCSyncSpace),
3434 ),
3535 mpb.AppendDecorators(
3636 decor.Percentage(decor.WC{W: 5}),
4141 defer wg.Done()
4242 max := 100 * time.Millisecond
4343 for !bar.Completed() {
44 startBlock <- time.Now()
44 sbEta <- time.Now()
4545 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
4646 bar.Increment()
4747 }