tasks

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	Task

	// Whether or not the executor is running
	IsRunning() bool
}

Executor is an implementation prototype for an object capable of running multiple tasks

func NewSerialExecutor

func NewSerialExecutor(tasks []Task, description string) Executor

NewSerialExecutor creates a new SerialExecutor, which can execute the slice of tasks serially.

type RunningExecutor

type RunningExecutor struct {
	// contains filtered or unexported fields
}

RunningExecutor is an implementation of RunningTask which executes an Executor on a separate go routine, then returns the result over a channel.

func (*RunningExecutor) Description

func (re *RunningExecutor) Description() string

Description returns the description of the executor.

func (*RunningExecutor) OnComplete

func (re *RunningExecutor) OnComplete() <-chan error

OnComplete returns the outbound channel that occurs when the executor is complete

type RunningTask

type RunningTask interface {
	// Description of the task.
	Description() string

	// The completion channel
	OnComplete() <-chan error
}

RunningTask is an implementation prototype for the execution of a task in the running state.

func ExecuteSerially

func ExecuteSerially(tasks []Task, description string) RunningTask

ExecuteSerially executes the provided tasks in order asynchronously via RunningTask, and returns the running task.

func RunExecutor

func RunExecutor(e Executor) RunningTask

RunExecutor creates a new RunningTask implementation and starts executing the Executor in a separate go routine

type SerialExecutor

type SerialExecutor struct {
	// contains filtered or unexported fields
}

SerialExecutor is a task executor which executes each child task serially. It also implements the Task interface so it can be used to represent a single task as well.

func (*SerialExecutor) Description

func (se *SerialExecutor) Description() string

Description returns a description of the execution steps.

func (*SerialExecutor) Execute

func (se *SerialExecutor) Execute() error

Executes each child task serially and reports any errors

func (*SerialExecutor) IsRunning

func (se *SerialExecutor) IsRunning() bool

Wheather or not the task is running

type Task

type Task interface {
	// Executes a task and returns an error of one occurs
	Execute() error

	// Description of the task.
	Description() string
}

Task is an implementation prototype that represents an executable task with status message

func TaskForError

func TaskForError(e error) Task

TaskFor returns a specific Task context for an error iff the error was a task error. Otherwise, nil is returned.

func TaskFromFunc

func TaskFromFunc(fn func() error, description string) Task

TaskFromFunc returns a Task implementation for a func() error.

type TaskQueue

type TaskQueue []Task

TaskQueue is a FIFO implementation for tasks.

func NewTaskQueue

func NewTaskQueue(tasks []Task) *TaskQueue

NewTaskQueue creates a new task queue and enqueues all tasks from the provided slice.

func (*TaskQueue) Dequeue

func (q *TaskQueue) Dequeue() Task

Deqeue removes the first item from the queue. If there are no items in the queue, nil is returned.

func (*TaskQueue) DrainTo

func (q *TaskQueue) DrainTo(buffer chan<- Task)

DrainTo drains the queue to a buffered channel of tasks. Note that this method could block if the buffered channel length is hit

func (*TaskQueue) Enqueue

func (q *TaskQueue) Enqueue(task Task) bool

Enqueue adds a Task to the queue.

func (*TaskQueue) IsEmpty

func (q *TaskQueue) IsEmpty() bool

IsEmpty returns true if the queue is empty.

func (*TaskQueue) Len

func (q *TaskQueue) Len() int

Len returns the length of the queue.

func (*TaskQueue) Peek

func (q *TaskQueue) Peek() Task

Peek returns the first Task in the queue or nil if the queue is empty

func (*TaskQueue) ReceiveFrom

func (q *TaskQueue) ReceiveFrom(buffer <-chan Task)

Enqueue tasks from an input channel buffer of tasks. Note that this method could block if the buffered channel isn't closed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL