Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownType is returned when the task type is not a valid value of Type. ErrUnknownType = errors.New("unknown task type") )
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps track of running goroutines and provides mechanisms to wait for them to finish or cancel their execution. `Meta` is whatever you wish to associate with this task, usually something that will help you keep track of the tasks in the observer.
func NewManager ¶
func NewManager() *Manager
NewManager creates a new instance of Manager with default options and no observer.
func NewManagerWithOptions ¶
NewManagerWithOptions creates a new instance of Manager with the provided options and observer.
func (*Manager) Cancel ¶
func (m *Manager) Cancel()
Cancel blocks until all loop tasks finish their current loop and stops looping further. The tasks' context is not cancelled. Adding a new loop task after calling Cancel() will cause the task to be ignored and not run.
func (*Manager) Close ¶
func (m *Manager) Close()
Close is a convenience method that calls Wait() and Cancel() in parallel. It blocks until all tasks have finished.
func (*Manager) CountOf ¶
CountOf returns the number of tasks of the specified type that are currently running. When the TaskType is invalid it returns 0.
type Options ¶
type Options struct { // StalledThreshold is the amount of time within which the task should return before it is considered stalled. Note // that no effort is made to actually stop or kill the task. StalledThreshold time.Duration // Observer allows you to register monitoring functions that are called when something happens with the tasks that you // execute. These are useful for logging, monitoring, etc. Observer observer.Observer // Retry defines the default retry strategies that will be used for all tasks unless overridden by the task. Several // strategies are provided by https://pkg.go.dev/github.com/kamilsk/retry/v5/strategy package. Retry task.Retry }
Options provides a means for configuring the background manager and providing the observer to it.