Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTaskPanic = fmt.Errorf("task panic occurred")
Functions ¶
Types ¶
type Multitask ¶
type Multitask struct { // ContinueOnError disables cancellation of sub context passed to // action callbackwhen it is not possible to start all N goroutines to // prepare an action. ContinueOnError bool // Goer starts a goroutine which executes a given task. // It is useful when client using some pool of goroutines. // // If nil, then default `go` is used and context is ignored. // // Non-nil error from Goer means that some resources are temporarily // unavailable and given task will not be executed. Goer GoerFn }
Multitask helps to run N tasks in parallel.
type TaskGroup ¶
type TaskGroup struct { // N is a maximum number of tasks TaskGroup can allow to execute. // If N is zero then TaskGroup with value 1 is used by default. N int // Goer starts a goroutine which executes a given task. // It is useful when client using some pool of goroutines. // // If nil, then default `go` is used and context is ignored. // // Non-nil error from Goer means that some resources are temporarily // unavailable and given task will not be executed. // // Note that for goroutine pool implementations it is required for pool to // have at least capacity of N goroutines. In other way deadlock may occur. Goer GoerFn // contains filtered or unexported fields }
TaskGroup helps to control execution flow of repeatable tasks. It is intended to execute at most N tasks at one time.
func (*TaskGroup) Cancel ¶
func (t *TaskGroup) Cancel()
Cancel cancels context of all currently running tasks. Further Do() calls will not be blocked on waiting for exit of previous tasks.
func (*TaskGroup) Do ¶
func (t *TaskGroup) Do(ctx context.Context, n int, task func(context.Context, int) error) []<-chan error
Do executes given function task in separate goroutine n minus <currently running tasks number> times. It returns slice of n channels which fulfillment means the end of appropriate task execution.
That is, for m already running tasks Do(n, n < m) will return n channels referring to a previously spawned task goroutines.
All currenlty executing tasks can be signaled to cancel by calling TaskGroup's Cancel() method.
nolint:gocognit
type TaskRunner ¶
type TaskRunner struct {
// contains filtered or unexported fields
}
TaskRunner runs only one task. Caller can subscribe to current task or in case if no task is running initiate a new one via Do method.
Check MAILX-1585 for details.
func (*TaskRunner) Cancel ¶
func (t *TaskRunner) Cancel()
type Throttle ¶
type Throttle struct {
// contains filtered or unexported fields
}
Throttle helps to run a function only a once per given time period.
func NewThrottle ¶
NewThrottle creates new Throttle with given period.