https://github.com/zmalik/go-routine-pool
A way to limit the parallelism while running multiple tasks
https://github.com/zmalik/go-routine-pool
go go-routine golang pool
Last synced: about 1 year ago
JSON representation
A way to limit the parallelism while running multiple tasks
- Host: GitHub
- URL: https://github.com/zmalik/go-routine-pool
- Owner: zmalik
- License: apache-2.0
- Created: 2018-05-04T06:43:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-04T07:29:35.000Z (about 8 years ago)
- Last Synced: 2025-02-01T23:41:18.361Z (over 1 year ago)
- Topics: go, go-routine, golang, pool
- Language: Go
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.MD
- License: LICENSE
Awesome Lists containing this project
README
# go-routine-pool
A way to limit the parallelism while running multiple tasks.
Under the hood it uses Go routines.
### Usage
```go
package main
import (
pool "github.com/zmalik/go-routine-pool"
)
func parallelTask(x int, y *int) int {
fmt.Printf("%d\n", x)
*y = x + *y
return x
}
func main() {
routinePool := pool.NewDefaultRoutinePool()
var result int
for i := 0; i < 20; i++ {
routinePool.Run(parallelTask, i, &result)
}
fmt.Println(result)
}
```
### Limiting number of Go routines
```go
routinePool := pool.NewRoutinePool(5)
```
## Why?
Power is nothing without control
Using Go routines one can easily rage the power of routines without limiting how many parallel tasks are running.
This library helps to control that in easy way