1
0
mirror of https://github.com/nxshock/gwp.git synced 2024-11-27 03:31:02 +05:00
Simple goroutine worker pool written in Go
Go to file
nxshock aba812a470 Some chages
* Use go-eta library from calculating ETA
* Fix linter issues
* Add testify library for tests
2022-08-06 22:13:22 +05:00
.gitattributes Initial commit 2021-02-01 20:15:05 +05:00
.gitignore Initial commit 2021-02-01 20:15:05 +05:00
consts_linux.go Upload code 2021-02-01 20:50:40 +05:00
consts_windows.go Upload code 2021-02-01 20:50:40 +05:00
consts.go Move consts to separate file 2021-02-03 20:57:44 +05:00
durationformat_test.go Add custom duration formatter 2022-01-08 18:40:23 +05:00
durationformat.go Add custom duration formatter 2022-01-08 18:40:23 +05:00
go.mod Some chages 2022-08-06 22:13:22 +05:00
go.sum Some chages 2022-08-06 22:13:22 +05:00
gwp_test.go Always update progress text at finish 2021-02-04 21:23:43 +05:00
gwp.go Some chages 2022-08-06 22:13:22 +05:00
LICENSE Initial commit 2021-02-01 20:15:05 +05:00
README.md Fix speed filed name 2022-03-08 18:00:09 +05:00

gwp

Simple goroutine worker pool written in Go.

Status: Work in progress.

Example:

package main

import (
	"log"
	"time"

	"github.com/nxshock/gwp"
)

// Job function
func f(i int) error {
	log.Printf("Job №%d", i)

	// Simulate work
	time.Sleep(time.Second)

	return nil
}

func main() {

	worker := gwp.New(4)       // Create pool with specified number of workers

	worker.ShowProgress = true // Enable progress indicator
	worker.ShowSpeed = true    // Show processing speed in progress indicator
	worker.EstimateCount = 100 // Set total number on jobs to calculate ETA

	for i := 0; i < 100; i++ {
		n := i
		// Send job
		worker.Add(func() error {
			return f(n)
		})
	}

	// Wait all jobs to complete
	worker.CloseAndWait()
}