Documentation
¶
Overview ¶
Package hofp exposes a generic higher order function pool which abstracts aways the logic/error handling required to perform tasks concurrently by wrapping complex tasks into a common 'func(context.Context) error' interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Function ¶
Function is a higher order function to be executed by the worker pool, where possible, the function should honor the cancellation of the given context and return as quickly/cleanly as possible.
type Options ¶
type Options struct {
// Context used by the worker pool, if omitted a background context will be used.
Context context.Context
// Size dictates the number of goroutines created to process incoming functions. Defaults to the number of vCPUs.
Size int
// BufferMultiplier is the multiplier used when determining how may functions can be buffered for processioning
// before calls to 'Queue' block. This value is multiplied by the number of goroutines, and defaults to one.
BufferMultiplier int
// Logger is the passed Logger struct that implements the Log method for logger the user wants to use.
Logger *slog.Logger
}
Options encapsulates the available options which can be used when creating a worker pool.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a generic higher order function worker pool which executes the provided functions concurrently using a configurable number of workers.
NOTE: Fails fast in the event of an error, subsequent attempts to use the worker pool will return the error which caused the pool to stop processing requests.
func NewPool ¶
NewPool returns a new higher order function worker pool with the provided number of workers.