當前位置: 首頁>>代碼示例>>Golang>>正文


Golang pb.StartNew函數代碼示例

本文整理匯總了Golang中github.com/cheggaaa/pb.StartNew函數的典型用法代碼示例。如果您正苦於以下問題:Golang StartNew函數的具體用法?Golang StartNew怎麽用?Golang StartNew使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了StartNew函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: HoldAuctionsFor

func HoldAuctionsFor(client types.RepPoolClient, instances []instance.Instance, representatives []string, rules types.AuctionRules, communicator types.AuctionCommunicator) ([]types.AuctionResult, time.Duration) {
	fmt.Printf("\nStarting Auctions\n\n")
	bar := pb.StartNew(len(instances))

	t := time.Now()
	semaphore := make(chan bool, rules.MaxConcurrent)
	c := make(chan types.AuctionResult)
	for _, inst := range instances {
		go func(inst instance.Instance) {
			semaphore <- true
			c <- communicator(types.AuctionRequest{
				Instance: inst,
				RepGuids: representatives,
				Rules:    rules,
			})
			<-semaphore
		}(inst)
	}

	results := []types.AuctionResult{}
	for _ = range instances {
		results = append(results, <-c)
		bar.Increment()
	}

	bar.Finish()

	return results, time.Since(t)
}
開發者ID:vito,項目名稱:auction,代碼行數:29,代碼來源:auctioneer.go

示例2: main

func main() {
	// Init...
	cfg := Config{
		CommonConfig: app.CommonConfig{
			MetaSize: 8,
			TileSize: 256,
		},
	}

	app.App.Configure("Copy", &cfg)

	if cfg.Copy.Threads < 1 {
		cfg.Copy.Threads = 1
	}

	fromI, err := plugins.DefaultPluginStore.Create(cfg.Copy.From.Plugin, cfg.Copy.From.PluginConfig)
	if err != nil {
		log.Fatal(err)
	}
	from, ok := fromI.(gopnik.CachePluginInterface)
	if !ok {
		log.Fatal("Invalid cache plugin type")
	}

	toI, err := plugins.DefaultPluginStore.Create(cfg.Copy.To.Plugin, cfg.Copy.To.PluginConfig)
	if err != nil {
		log.Fatal(err)
	}
	to, ok := toI.(gopnik.CachePluginInterface)
	if !ok {
		log.Fatal("Invalid cache plugin type")
	}

	// Load plan...
	coords, err := loadPlanFile()
	if err != nil {
		log.Fatal(err)
	}

	// Process...
	bar := pb.StartNew(len(coords))
	var barMu sync.Mutex
	var wg sync.WaitGroup

	for k := 0; k < cfg.Copy.Threads; k++ {
		wg.Add(1)
		go func(k int) {
			defer wg.Done()
			for i := k; i < len(coords); i += cfg.Copy.Threads {
				copyMetaTile(coords[i], &cfg, from, to)

				barMu.Lock()
				bar.Increment()
				barMu.Unlock()
			}
		}(k)
	}
	wg.Wait()
	bar.FinishPrint("Done")
}
開發者ID:mikhailborodin,項目名稱:gopnik,代碼行數:60,代碼來源:main.go

示例3: getInitTweets

func (g *Game) getInitTweets(aliveNum int) {
	var progress *pb.ProgressBar
	if !g.debug {
		progress = pb.StartNew(aliveNum)
	}
	for y := 0; y < g.field.SizeY; y++ {
		for x := 0; x < g.field.SizeX; x++ {
			if g.field.Points[y][x].IsAlive {
				tweet := <-g.tweetCh
				if g.debug {
					emoji.Printf(":bird:Points[%v][%v]: %v\n", x, y, tweet)
				}
				g.field.Points[y][x].Str = tweet
				if !g.debug {
					progress.Increment()
				}
			}
		}
	}
	if g.debug {
		emoji.Println(":smile::smile::smile:Collected initial tweets:smile::smile::smile:")
	} else {
		e := emoji.Sprint(":smile::smile::smile:")
		progress.FinishPrint(e + "Collected initial tweets" + e)
	}
}
開發者ID:Rompei,項目名稱:lgb,代碼行數:26,代碼來源:game.go

示例4: HostMerge

func HostMerge(List []Host, ShowBar bool) []string {
	count := 0
	filterList := []string{""}
	length := len(List)
	var bar *pb.ProgressBar
	if ShowBar == true {
		bar = pb.StartNew(length)
		bar.SetMaxWidth(80)
	}
	for _, Host := range List {
		length = len(filterList[count])
		if length == 0 {
			filterList[count] = Host.Hostname
		} else if length+Host.length() <= 255 && length != 0 {
			filterList[count] += "|"
			filterList[count] += Host.Hostname
		} else {
			count++
			filterList = append(filterList, Host.Hostname)
			// filterList[count] = Ref.Referrer
		}
		if ShowBar == true {
			bar.Increment()
			time.Sleep(time.Millisecond * 50)
		}
	}
	if ShowBar == true {
		bar.Finish()
	}
	return filterList
}
開發者ID:botsifter,項目名稱:BotSifter-Go-Client,代碼行數:31,代碼來源:botsifter.go

示例5: doUpload

func doUpload(filelist []string) {
	length := len(filelist)

	if length == 0 {
		fmt.Println("No new tiles to upload")
		return
	}

	pb.BarStart = "["
	pb.BarEnd = "]"
	pb.Empty = " "
	pb.Current = "#"
	pb.CurrentN = ">"

	bar := pb.StartNew(length)

	c := initWorkers()
	go func() {
		for i := 0; i < length; i++ {
			uploadFile(filelist[i])
		}
	}()

	var total int
	for total < length {
		select {
		case <-c:
			total = total + 1
			bar.Increment()
		}
	}

	bar.Finish()
}
開發者ID:scottferg,項目名稱:MC-Map-Uploader,代碼行數:34,代碼來源:main.go

示例6: main

func main() {
	jobs := makeJobs(ipNetParsed, 100)
	out := make(chan ILOInfo, 100)
	ipNetLen := len(ipNetParsed)

	scanbar := pb.StartNew(ipNetLen)
	scanbar = scanbar.Prefix("Scan net")
	scanbar.ShowTimeLeft = false

	wg := new(sync.WaitGroup)
	//Запуск воркеров
	for _, job := range jobs {
		wg.Add(1)
		go scan(job, out, scanbar, wg)
	}

	wg.Wait()
	close(out)

	ilo := []ILOInfo{}
	for info := range out {
		ilo = append(ilo, info)
	}
	scanbar.Finish()
	tableRender(ilo)
	fmt.Println("")
}
開發者ID:hdhog,項目名稱:findilo,代碼行數:27,代碼來源:main.go

示例7: GenerateTestData

func GenerateTestData(
	directory string,
	fileCount, rowCount int,
	timeOrigin int64, timeDistance int,
	uidCount int,
	domainsFilename string,
	geoOrigin util.GeoPoint, geoDistance int,
) (filenames []string, err error) {
	domains, err := newDomains(domainsFilename)
	if err != nil {
		return nil, err
	}
	filenames = make([]string, fileCount)
	progressBar := pb.StartNew(fileCount)
	for i := 0; i < fileCount; i++ {
		filename, err := generateTestDataFile(
			directory,
			rowCount,
			timeOrigin, timeDistance,
			uidCount,
			domains,
			geoOrigin, geoDistance,
		)
		if err != nil {
			return nil, err
		}
		progressBar.Increment()
		filenames[i] = filename
	}
	progressBar.FinishPrint("All done!")
	return filenames, nil
}
開發者ID:habajca,項目名稱:simple-log-search,代碼行數:32,代碼來源:main.go

示例8: main

func main() {
	// declare flags
	regionPtr := flag.String("region", "us-east-2", "AWS Region(default: us-east-2)")
	bucketPtr := flag.String("bucket", "backup", "Bucket path you wish to upload")
	srcPtr := flag.String("src", os.Getenv("PWD"), "src folder of files (default this folder)")
	keyPtr := flag.String("key", os.Getenv("AWS_ACCESS_KEY_ID"), "AWS_ACCESS_KEY_ID")
	secretPtr := flag.String("secret", os.Getenv("AWS_SECRET_ACCESS_KEY"), "AWS_SECRET_ACCESS_KEY")
	destPtr := flag.String("dest", "new", "Destination path of root directory where you wish the contents to go in the bucket, \nif your connection continues to timeout try lowering it")
	limitPtr := flag.Int("limit", "4", "Number of concurrent uploads")

	flag.BoolVar(&timeStamp, "timestamp", false, "append commitstamp to the destination the commit")
	flag.BoolVar(&debug, "debug", false, "enable debug mode")

	flag.Parse()

	p := []string{
		*destPtr,
	}

	if timeStamp {
		p = append(p, strconv.FormatInt(time.Now().Unix(), 10))
	}

	dest := strings.Join(p, ".")
	fmt.Println(dest)
	simpleS3 := s5.New(*srcPtr, dest, *bucketPtr, *keyPtr, *secretPtr, *regionPtr, *limitPtr, debug)
	bar := pb.StartNew(simpleS3.FileCount)
	bar.ShowTimeLeft = false
	bar.Format("[⚡- ]")

	simpleS3.Run(func() {
		bar.Increment()
	})
	bar.FinishPrint(fmt.Sprintf("Completed Uploading to %s/%s!", simpleS3.Bucket, simpleS3.Dest))
}
開發者ID:dring1,項目名稱:stupid-simple-s3-backup,代碼行數:35,代碼來源:main.go

示例9: init

func (b *Boom) init() {
	if b.Client == nil {
		b.Client = &http.Client{}
	}
	b.results = make(chan *result, b.N)
	b.bar = pb.StartNew(b.N)
	b.start = time.Now()
}
開發者ID:kkbankol,項目名稱:boom,代碼行數:8,代碼來源:run.go

示例10: ReadDB

func ReadDB(c *client.Client, sdb, ddb, cmd string) client.BatchPoints {

	q := client.Query{
		Command:  cmd,
		Database: sdb,
	}

	//get type client.BatchPoints
	var batchpoints client.BatchPoints

	response, err := c.Query(q)
	if err != nil {
		fmt.Printf("Fail to get response from database, read database error: %s\n", err.Error())
	}

	res := response.Results
	if len(res) == 0 {
		fmt.Printf("The response of database is null, read database error!\n")
	} else {

		res_length := len(res)
		for k := 0; k < res_length; k++ {

			//show progress of reading series
			count := len(res[k].Series)
			bar := pb.StartNew(count)
			for _, ser := range res[k].Series {

				//get type client.Point
				var point client.Point

				point.Measurement = ser.Name
				point.Tags = ser.Tags
				for _, v := range ser.Values {
					point.Time, _ = time.Parse(time.RFC3339, v[0].(string))

					field := make(map[string]interface{})
					l := len(v)
					for i := 1; i < l; i++ {
						if v[i] != nil {
							field[ser.Columns[i]] = v[i]
						}
					}
					point.Fields = field
					point.Precision = "s"
					batchpoints.Points = append(batchpoints.Points, point)
				}
				bar.Increment()
				time.Sleep(3 * time.Millisecond)
			}
			bar.FinishPrint("Read series has finished!\n")
		}
		batchpoints.Database = ddb
		batchpoints.RetentionPolicy = "default"
	}
	return batchpoints
}
開發者ID:guaiguaihw,項目名稱:influxdb-move,代碼行數:57,代碼來源:client.go

示例11: runDBTasks

func runDBTasks(ids []int64, task func(int64) error) {

	// Progress bar
	bar := pb.StartNew(len(ids))

	// Cancel control
	done := make(chan struct{})
	quit := false

	// IDs to process, sent via channel
	tasks := make(chan int64, len(ids)+1)

	var errs []error
	var wg sync.WaitGroup

	// Only fire up a set number of worker processes
	for i := 0; i < getGophers(len(ids)); i++ {
		wg.Add(1)

		go func() {
			for id := range tasks {
				err := doTask(id, task, done)
				if err != nil {
					if !quit {
						close(done)
						quit = true
					}
					errs = append(
						errs,
						fmt.Errorf("Failed on ID %d : %+v", id, err),
					)
					break
				}
				bar.Increment()
			}
			wg.Done()
		}()
	}

	for _, id := range ids {
		tasks <- id
	}
	close(tasks)

	wg.Wait()
	if !quit {
		close(done)
	}

	if len(errs) == 0 {
		bar.Finish()
	}

	for _, err := range errs {
		handleErr(err)
	}
}
開發者ID:siparker,項目名稱:export-vbulletin,代碼行數:57,代碼來源:db.go

示例12: Wait

func (c *ContentQueue) Wait() {
	finished := 0
	bar := pb.StartNew(len(c.items))
	for finished < len(c.items) {
		<-c.items[finished].Result
		finished++
		bar.Increment()
	}
	bar.Finish()
}
開發者ID:rubenv,項目名稱:sitegen,代碼行數:10,代碼來源:sitegen.go

示例13: init

func (b *Boom) init() {
	if b.Client == nil {
		tr := &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: b.AllowInsecure},
		}
		b.Client = &http.Client{Transport: tr}
	}
	b.results = make(chan *result, b.N)
	b.bar = pb.StartNew(b.N)
	b.start = time.Now()
}
開發者ID:josephyzhou,項目名稱:boom,代碼行數:11,代碼來源:run.go

示例14: main

func main() {
	count := 6000
	bar := pb.StartNew(count)
	for i := 0; i < count; i++ {
		bar.Increment()
		time.Sleep(time.Millisecond)
	}
	bar.ShowBar = true
	bar.ShowSpeed = true
	bar.FinishPrint("The End!")
}
開發者ID:sumory,項目名稱:gogist,代碼行數:11,代碼來源:progress.go

示例15: unzip

func unzip(filename, dest, ver string) {
	var path string
	if filename == "" {
		fmt.Println("Can't unzip ", filename)
		os.Exit(1)
	}

	/* if filename[:2] == "go" {
		dest = dest + ps + strings.Replace(filename, "go", "go"+ps+ver, 1)
	} else if filename[:2] == "li" {
		dest = dest + ps + strings.Replace(filename, "liteide", "liteide"+ps+ver, 1)
	} */

	reader, err := zip.OpenReader(filename)
	checkErr("Extract error::OpenArchive", err)
	defer reader.Close()

	fl := int(len(reader.Reader.File))
	bar := pb.StartNew(fl)
	bar.ShowPercent = true
	bar.ShowCounters = false
	bar.ShowTimeLeft = false
	bar.Prefix("Extracting " + filename[strings.LastIndex(filename, ps)+1:] + " ")
	bar.Start()
	for _, f := range reader.Reader.File {
		zipped, err := f.Open()
		checkErr("Extract error::", err)
		defer zipped.Close()

		// path := filepath.Join(dest, ver, "./", f.Name)
		if f.Name[:2] == "go" {
			path = filepath.Join(dest, "./", strings.Replace(f.Name, "go", "go"+ps+ver, 1))
		} else if f.Name[:2] == "li" {
			path = filepath.Join(dest, "./", strings.Replace(f.Name, "liteide", "liteide"+ps+ver, 1))
		}
		// fmt.Println(path)

		if f.FileInfo().IsDir() {
			os.MkdirAll(path, f.Mode())
		} else {
			writer, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, f.Mode())
			checkErr("Extract error::OpenFileFromArchive", err)
			defer writer.Close()

			if _, err = io.Copy(writer, zipped); err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
		}
		//  progress = (i / fl) * 100
		bar.Increment()
	}
	bar.Finish()
}
開發者ID:bvp,項目名稱:gtvm,代碼行數:54,代碼來源:extract.go


注:本文中的github.com/cheggaaa/pb.StartNew函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。