Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivpusic/grpool
Lightweight Goroutine pool
https://github.com/ivpusic/grpool
golang goroutine pool workers
Last synced: about 2 months ago
JSON representation
Lightweight Goroutine pool
- Host: GitHub
- URL: https://github.com/ivpusic/grpool
- Owner: ivpusic
- License: mit
- Created: 2015-07-22T00:15:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-27T23:07:22.000Z (almost 6 years ago)
- Last Synced: 2024-07-31T20:51:54.252Z (5 months ago)
- Topics: golang, goroutine, pool, workers
- Language: Go
- Homepage: https://godoc.org/github.com/ivpusic/grpool
- Size: 19.5 KB
- Stars: 741
- Watchers: 31
- Forks: 101
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - grpool - Lightweight Goroutine pool. (Goroutines / Search and Analytic Databases)
- awesome-go - grpool - Lightweight Goroutine pool - ★ 428 (Goroutines)
- awesome-go-extra - grpool - 07-22T00:15:04Z|2019-01-27T23:07:22Z| (Goroutines / Advanced Console UIs)
README
# grpool
[![Build Status](https://travis-ci.org/ivpusic/grpool.svg?branch=master)](https://travis-ci.org/ivpusic/grpool)Lightweight Goroutine pool
Clients can submit jobs. Dispatcher takes job, and sends it to first available worker.
When worker is done with processing job, will be returned back to worker pool.Number of workers and Job queue size is configurable.
## Docs
https://godoc.org/github.com/ivpusic/grpool## Installation
```
go get github.com/ivpusic/grpool
```## Simple example
```Go
package mainimport (
"fmt"
"runtime"
"time""github.com/ivpusic/grpool"
)func main() {
// number of workers, and size of job queue
pool := grpool.NewPool(100, 50)// release resources used by pool
defer pool.Release()// submit one or more jobs to pool
for i := 0; i < 10; i++ {
count := ipool.JobQueue <- func() {
fmt.Printf("I am worker! Number %d\n", count)
}
}// dummy wait until jobs are finished
time.Sleep(1 * time.Second)
}
```## Example with waiting jobs to finish
```Go
package mainimport (
"fmt"
"runtime""github.com/ivpusic/grpool"
)func main() {
// number of workers, and size of job queue
pool := grpool.NewPool(100, 50)
defer pool.Release()// how many jobs we should wait
pool.WaitCount(10)// submit one or more jobs to pool
for i := 0; i < 10; i++ {
count := ipool.JobQueue <- func() {
// say that job is done, so we can know how many jobs are finished
defer pool.JobDone()fmt.Printf("hello %d\n", count)
}
}// wait until we call JobDone for all jobs
pool.WaitAll()
}
```## License
*MIT*