executor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExecSkipped = errors.New("not executed")
	ErrPanic       = errors.New("panic error")
)

Functions

This section is empty.

Types

type Executor

type Executor struct {
	Tasks *TaskMap
	// contains filtered or unexported fields
}

func NewExecutor

func NewExecutor() *Executor

NewExecutor creates a new Executor instance with a new TaskMap.

func (*Executor) Add

func (e *Executor) Add(id string, t *Task)

Add adds a task to the executor.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context) TaskResult

Execute runs every task and wait until every task is executed.

type Task

type Task struct {
	Id        string
	Fn        func() error
	DependsOn []string
	Err       error // execution error
	Running   bool  // this task is running
	Skip      bool  // this task is skipped due to an error from prior tasks
	// contains filtered or unexported fields
}

Task is an object representing a named task and its next tasks.

func (*Task) IsDone

func (t *Task) IsDone() bool

func (*Task) MarkDone

func (t *Task) MarkDone()

type TaskMap

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

TaskMap is a synchronized map to store tasks using its Id as a key.

func NewTaskMap

func NewTaskMap() *TaskMap

func (*TaskMap) AddTask

func (t *TaskMap) AddTask(k *Task)

func (*TaskMap) Count

func (t *TaskMap) Count() int

func (*TaskMap) Get

func (t *TaskMap) Get(id string) *Task

func (*TaskMap) GetTaskIds

func (t *TaskMap) GetTaskIds() []string

func (*TaskMap) Range

func (t *TaskMap) Range(iterFn func(string, *Task) bool)

func (*TaskMap) RemoveTask

func (t *TaskMap) RemoveTask(k *Task)

type TaskResult

type TaskResult []*Task

func (*TaskResult) Error

func (t *TaskResult) Error() string

Error returns a combined error message.

func (*TaskResult) HasError

func (t *TaskResult) HasError() bool

type TriggerSet

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

TriggerSet is a set that returns true if the set is empty after removing an item. Its functions are all thread-safe.

func NewTriggerSet

func NewTriggerSet() *TriggerSet

func (*TriggerSet) Add

func (t *TriggerSet) Add(id string)

func (*TriggerSet) Remove

func (t *TriggerSet) Remove(id string) bool

Jump to

Keyboard shortcuts

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