gitee.com/quant1x/gox@v1.21.2/progressbar/demo/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/gox/logger"
     6  	"sync"
     7  	"time"
     8  
     9  	pgbar "gitee.com/quant1x/gox/progressbar"
    10  )
    11  
    12  func progressBarTest() {
    13  	fmt.Printf("\n\n\n")
    14  	b := pgbar.NewBar(1, "1st", 20000)
    15  	b2 := pgbar.NewBar(2, "2st", 10000)
    16  	b3 := pgbar.NewBar(3, "3st", 30000)
    17  	b4 := pgbar.NewBar(4, "4st", 4000)
    18  	b.SetSpeedSection(900, 100)
    19  	b2.SetSpeedSection(900, 100)
    20  	b3.SetSpeedSection(900, 100)
    21  
    22  	var wg sync.WaitGroup
    23  	wg.Add(4)
    24  	go func() {
    25  		defer wg.Done()
    26  		for i := 0; i < 20000; i++ {
    27  			b.Add(1)
    28  			time.Sleep(time.Second / 2000)
    29  		}
    30  	}()
    31  
    32  	go func() {
    33  		defer wg.Done()
    34  		for i := 0; i < 10000; i++ {
    35  			b2.Add(1)
    36  			time.Sleep(time.Second / 1000)
    37  		}
    38  	}()
    39  	go func() {
    40  		defer wg.Done()
    41  		for i := 0; i < 30000; i++ {
    42  			b3.Add(1)
    43  			time.Sleep(time.Second / 3000)
    44  		}
    45  	}()
    46  
    47  	go func() {
    48  		defer wg.Done()
    49  		for i := 0; i < 4000; i++ {
    50  			b4.Add(1)
    51  			time.Sleep(time.Second / 300)
    52  		}
    53  	}()
    54  	wg.Wait()
    55  }
    56  
    57  func main() {
    58  	logger.InitLogger("/opt/logs/test", logger.INFO)
    59  	for i := 0; i < 100; i++ {
    60  		progressBarTest()
    61  		fmt.Printf("\n\n\n\n\n====================================================================================================")
    62  	}
    63  }