Documentation
¶
Index ¶
- func Work[I, O any](work func(I) O) poolWork[I, O]
- func WorkSimple[I any](work func(I)) poolWork[I, noValue]
- func WorkSimpleWithErrors[I any](work func(I) error) poolWork[I, noValue]
- func WorkWithErrors[I, O any](work func(I) (O, error)) poolWork[I, O]
- type Pool
- func (p *Pool[_, _]) Close(force ...bool)
- func (p *Pool[I, O]) Connect(parent PoolConnector[O]) error
- func (p *Pool[_, _]) Debug()
- func (p Pool[I, _]) Errors() (chan PoolError[I], error)
- func (p Pool[_, _]) IsClosed() bool
- func (p Pool[_, _]) IsConnected() bool
- func (p Pool[_, _]) JobsCompleted() int64
- func (p Pool[_, _]) JobsSucceeded() int64
- func (p Pool[_, _]) JobsWaiting() int64
- func (p *Pool[_, _]) Name() string
- func (p Pool[_, O]) Outputs() (chan O, error)
- func (p *Pool[_, _]) SetLevel(level log.Level)
- func (p Pool[I, _]) Submit(job I) error
- func (p Pool[_, _]) Wait()
- type PoolConnector
- type PoolError
- type Settings
- type Signal
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Work ¶
func Work[I, O any](work func(I) O) poolWork[I, O]
Work should be used to set work with outputs but no errors.
func WorkSimple ¶
func WorkSimple[I any](work func(I)) poolWork[I, noValue]
WorkSimple should be used to set work with no outputs nor errors.
func WorkSimpleWithErrors ¶
WorkSimpleWithErrors should be used to set work with no outputs but with errors.
func WorkWithErrors ¶
WorkWithErrors should be used to set work with both outputs and errors.
Types ¶
type Pool ¶
type Pool[I, O any] struct { // contains filtered or unexported fields }
Pool is a fantastic golang pool that can take work of any form and perform it in a go-idiomatic way of producing outputs (optional) and errors (optional).
func NewWithSettings ¶
NewWithSettings creates a new pool with custom pool tunings enabled.
func (*Pool[_, _]) Close ¶
Close will issue a pool closure request and takes a bool value, if true, any pending jobs will be ignored and forcefully closed. Note that the user can request a pool closure if and only if it is not connected to another pool. In that case, the parent pool will have to issue the closure request.
func (*Pool[I, O]) Connect ¶
func (p *Pool[I, O]) Connect(parent PoolConnector[O]) error
func (*Pool[_, _]) Debug ¶
func (p *Pool[_, _]) Debug()
Debug enables the debug logging in the pool.
func (Pool[I, _]) Errors ¶
Errors returns a channel of errors generated by the pool, nil if pool is closed, doesn't produce errors, or an error handler is set.
func (Pool[_, _]) IsConnected ¶
IsConnected will return true if this pool already has an active connector. This is equivalent to having a connected (parent) pool.
func (Pool[_, _]) JobsCompleted ¶
JobsCompleted will return the number of jobs completed by the pool.
func (Pool[_, _]) JobsSucceeded ¶
JobsSucceeded will return the number of jobs succeeded (non-nil errors).
func (Pool[_, _]) JobsWaiting ¶
JobsWaiting will return the number of jobs currently waiting and executing by the pool.
func (Pool[_, O]) Outputs ¶
Outputs returns a channel of outputs generated by the pool, nil if pool is closed or doesn't produce outputs.
type PoolConnector ¶
type PoolConnector[O any] interface { // Submit will submit a job to the connected (parent) pool. Submit(O) error // IsClosed returns true if the connected (parent) pool is closed, // false otherwise. IsClosed() bool // Name returns the name of the connected (parent) pool. Name() string // contains filtered or unexported methods }
PoolConnector is an interface that should be used by other pools when connecting to them and by users to send pools around as well.
type PoolError ¶
type PoolError[I any] struct { // Job is the job that returned a non-nil error when work was performed on it. Job I // Error is the error returned by pool's work performer. Error error }
PoolError is produced by the pool when a work performed by the pool fails with a non-nil error, so the user can debug and look what happened.
type Settings ¶
type Settings struct {
// Laborers is the number of laborers (work performers) that should
// run in parallel.
Laborers int
// Size sets the Size of the pool, or how many inputs and outputs (each
// has separate Size) can be set by the pool. If Size is reached, submissions
// or work results will be blocked.
Size int
// Ratio is the ratio that is used (unless size is set manually)
// for setting the size to the number of laborers.
Ratio int
// Debug will set the logger to show all Debug logs too.
Debug bool
// Name is the Name of the pool.
Name string
// LogLevel defaults to warn, can be set by the user.
LogLevel log.Level
// contains filtered or unexported fields
}
Settings is an internal struct that tunes the pool as requested.
