Documentation ¶
Overview ¶
Package executor contains a task executor and its related utilities. A task executor provides a simple interface for concurrently conducting multiple small number of tasks using a single goroutine for each one. It offers a signals channel to control the executor itself and a reports channel to get reports of the tasks as they get completed. The Task and Report are both interfaces and the client can specify any kind of logic in them. But it is recommended that a Task should be something that is simple and individual and should NOT spawn further goroutines. User can control the maximum simultaneous goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor struct { ActiveWorkers int64 Tasks chan Task Reports chan Report // contains filtered or unexported fields }
The Executor struct is the main executor for tasks. 'maxWorkers' represents the maximum number of simultaneous goroutines. 'ActiveWorkers' tells the number of active goroutines spawned by the Executor at given time. 'Tasks' is the channel on which the Executor receives the tasks. 'Reports' is channel on which the Executor publishes the every tasks reports. 'signals' is channel that can be used to control the executor. Right now, only the termination signal is supported which is essentially is sending '1' on this channel by the client.
func NewExecutor ¶
NewExecutor creates a new Executor. 'maxWorkers' tells the maximum number of simultaneous goroutines. 'signals' channel can be used to control the Executor.
func (*Executor) AddTask ¶
AddTask is used to submit a new task to the Executor is a non-blocking way. The Client can submit a new task using the Executor's tasks channel directly but that will block if the tasks channel is full. It should be considered that this method doesn't add the given task if the tasks channel is full and it is up to client to try again later.