task

package
v0.0.0-...-baa1297 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Priority

type Priority int

Priority represents the priority level of a task.

const (
	// LowPriority represents a low-priority task.
	LowPriority Priority = iota

	// MediumPriority represents a medium-priority task.
	MediumPriority

	// HighPriority represents a high-priority task.
	HighPriority
)

type Task

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

Task represents a unit of work that can be executed concurrently.

func NewTask

func NewTask(id string, fn func(context.Context) error, priority Priority) *Task

NewTask creates a new task with the given ID, function, and priority.

func (*Task) AddDependency

func (t *Task) AddDependency(dependency *Task)

AddDependency adds a dependency to the task.

func (*Task) Cancel

func (t *Task) Cancel()

Cancel stops the task's execution if it's currently running.

func (*Task) Dependencies

func (t *Task) Dependencies() []*Task

Dependencies returns the task's dependencies.

func (*Task) Execute

func (t *Task) Execute(ctx context.Context) error

Execute runs the task and returns any error encountered during execution.

func (*Task) ID

func (t *Task) ID() string

ID returns the task's unique identifier.

func (*Task) IsReady

func (t *Task) IsReady() bool

IsReady returns true if the task has no dependencies or all of its dependencies have completed execution.

func (*Task) Priority

func (t *Task) Priority() Priority

Priority returns the task's priority level.

func (*Task) RemoveDependency

func (t *Task) RemoveDependency(dependency *Task)

RemoveDependency removes a dependency from the task.

func (*Task) SetPriority

func (t *Task) SetPriority(priority Priority)

SetPriority sets the task's priority level.

func (*Task) Wait

func (t *Task) Wait(ctx context.Context) error

Wait blocks until the task has completed execution or the context is canceled.

Jump to

Keyboard shortcuts

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