Documentation
¶
Overview ¶
Package worker implements a service to process work concurrently.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsInvalidConfig ¶
IsInvalidConfig asserts invalidConfigError.
Types ¶
type ExecuteConfig ¶
type ExecuteConfig struct {
// Actions represents the function executed by worker goroutines. The given
// context is the context provided to the call to Service.Execute.
Actions []func(ctx context.Context) error
// CancelOnError defines whether to signal cancelation of worker goroutines in
// case one worker of the pool throws an error.
CancelOnError bool
// Errors is the channel used to put all occured errors into, if any. When
// this is provided manually the caller have to make sure the errors channel
// is buffered according to the number of provided actions.
Errors chan error
// NumWorkers represents the number of workers to be registered to run
// concurrently within the pool.
NumWorkers int
}
ExecuteConfig represents the configuration used to execute a new worker pool.
type Service ¶
type Service interface {
// Execute processes all configured actions concurrently. The call to Execute
// blocks until all goroutines within the worker pool have finished their
// work.
Execute(ctx context.Context, config ExecuteConfig) error
// ExecuteConfig provides a default configuration for Execute.
ExecuteConfig() ExecuteConfig
}
Service represents a service to process work concurrently.
func NewService ¶
func NewService(config ServiceConfig) (Service, error)
NewService creates a new configured worker service.
type ServiceConfig ¶
type ServiceConfig struct {
}
ServiceConfig represents the configuration used to create a new worker service.
func DefaultServiceConfig ¶
func DefaultServiceConfig() ServiceConfig
DefaultServiceConfig provides a default configuration to create a new worker service by best effort.
Click to show internal directories.
Click to hide internal directories.