Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( // DefaultMinWorkers is the default minimum number of workers to keep alive. DefaultMinWorkers = 0 // DefaultIdleTimeout is the default timeout for idle workers. DefaultIdleTimeout = 2 * time.Second )
const ( // Opened represents that the Rego is opened. Opened = iota // Closed represents that the Rego is closed. Closed )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
Option represents the optional function.
func WithIdleTimeout ¶
WithIdleTimeout sets the idle timeout.
func WithMinWorkers ¶
WithMinWorkers sets the minimum number of workers.
type Rego ¶
type Rego struct {
Stop int
// contains filtered or unexported fields
}
Rego is a goroutine pool.
func New ¶
New instantiates a Rego with customized options. The size parameter specifies the capacity of Rego, which is the maximum number of workers that can execute tasks concurrently.
func (*Rego) MinWorkers ¶
MinWorkers returns the minimum number of workers that can keep alive.
func (*Rego) Release ¶
func (r *Rego) Release()
Release closes the Rego but ignores all waiting tasks. Tasks should not be submitted after closing the Rego.
func (*Rego) ReleaseWait ¶
func (r *Rego) ReleaseWait()
ReleaseWait closes the Rego and waits for all tasks to complete. Tasks should not be submitted after closing the Rego.
func (*Rego) Submit ¶
func (r *Rego) Submit(task func())
Submit submits a task to the Rego.
Example ¶
package main
import (
"fmt"
"github.com/alilestera/rego"
)
func main() {
r := rego.New(3)
defer r.ReleaseWait()
requests := []string{"alpha", "beta", "gamma", "delta", "epsilon"}
for _, v := range requests {
r.Submit(func() {
fmt.Println(v)
})
}
}
Output: alpha beta gamma delta epsilon
func (*Rego) SubmitWait ¶
func (r *Rego) SubmitWait(task func())
SubmitWait submits a task to the Rego and waits for it to complete.
Example ¶
package main
import (
"fmt"
"github.com/alilestera/rego"
)
func main() {
r := rego.New(3)
defer r.ReleaseWait()
requests := []string{"foo", "bar", "foobar", "anything", "else"}
for _, v := range requests {
r.SubmitWait(func() {
fmt.Println(v)
})
}
}
Output: foo bar foobar anything else