Documentation
¶
Overview ¶
Package concurrent contains some easy-to-use concurrent control utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
// Runner is a func need to be executed. It may return a list of new
// actions. These actions will be executed after the current action had
// finished
Runner func() []Action
// Dependencies for the current action. The current action will only be
// executed after all dependencies had been finished
Dependencies []Action
}
Action to be run concurrently
type ActionPool ¶
type ActionPool interface {
// Do an action. It's panic-free if using it correctly.
// It will panic if you do an action in a closed pool.
Do(Action)
// Map returns a slice of result that applies `f` to every item of `input`.
// The `ret` is in-order.
Map(input []interface{}, f func(interface{}) interface{}) (ret []interface{})
// Wait until all the actions had been finished.
Wait()
// Wait until all the actions had been finished, and close the pool.
WaitAndClose()
// Set a logger to output some err msg when panic. os.Stderr will be used
// by default.
SetLogger(io.Writer)
}
ActionPool is an action pool based on goroutines
func NewActionPool ¶
func NewActionPool(maxConcurrent int) ActionPool
NewActionPool creates a new concurrent action pool. if maxConcurrent <= 0, then the real maxConcurrent will be runtime.NumCPU()
Click to show internal directories.
Click to hide internal directories.