1 Star 0 Fork 10

YangMain / goProgressor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
incr.go 838 Bytes
一键复制 编辑 原始数据 按行查看 历史
githubvip 提交于 2019-11-29 16:18 . commit
package main
import (
"fmt"
"math/rand"
"runtime"
"sync"
"time"
"gitee.com/shirdonl/goProgressor"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) // use all available cpu cores
// create a new bar and prepend the task progress to the bar and fanout into 1k go routines
count := 1000
bar := goprogressor.AddBar(count).AppendCompleted().PrependElapsed()
bar.PrependFunc(func(b *goprogressor.Bar) string {
return fmt.Sprintf("Task (%d/%d)", b.Current(), count)
})
goprogressor.Start()
var wg sync.WaitGroup
// fanout into 1k go routines
for i := 0; i < count; i++ {
wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(time.Millisecond * time.Duration(rand.Intn(500)))
bar.Incr()
}()
}
time.Sleep(time.Second) // wait for a second for all the go routines to finish
wg.Wait()
goprogressor.Stop()
}
Go
1
https://gitee.com/yangmain/goProgressor.git
git@gitee.com:yangmain/goProgressor.git
yangmain
goProgressor
goProgressor
master

搜索帮助