rego means recycle goroutines and reduce goroutines
Library rego is a lightweight goroutine pool implementation that controls concurrent resources by reusing goroutines. Developers can significantly reduce memory growth in concurrent programs with minimal performance trade-offs.
go get -u github.com/alilestera/regoYou need to call rego.New to instantiate a Rego with a given capacity:
r := rego.New(100)You can call r.Submit() submit tasks:
r.Submit(func() {})If you need to close Rego:
r.Release() // close Rego and ignore all waiting tasksor
r.ReleaseWait() // close Rego and wait all tasks donepackage main
import (
"fmt"
"github.com/alilestera/rego"
)
func main() {
r := rego.New(100)
r.Submit(func() {
fmt.Println("hello world")
})
r.ReleaseWait()
}| Option | Default | Description |
|---|---|---|
| WithMinWorkers | 0 | Set the minimum number of active workers |
| WithIdleTimeout | 2 * time.Second | Set the idle timeout of active worker |
r := rego.New(100, rego.WithMinWorkers(10), rego.WithIdleTimeout(5*time.Second))This project was inspired by or benefited from the following repositories:
The source code in rego is licensed under Apache License 2.0.