queue

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

type Task[T any] struct {
	ID    string
	Title string
	Data  T
	// contains filtered or unexported fields
}

func NewTask

func NewTask[T any](ctx context.Context, id string, title string, data T) *Task[T]

func (*Task[T]) Cancel

func (t *Task[T]) Cancel()

func (*Task[T]) Cancelled added in v0.43.0

func (t *Task[T]) Cancelled() bool

func (*Task[T]) Context

func (t *Task[T]) Context() context.Context

type TaskInfo added in v0.43.0

type TaskInfo struct {
	ID        string
	Created   time.Time
	Cancelled bool
	Title     string
}

Read-only info about a task

type TaskQueue

type TaskQueue[T any] struct {
	// contains filtered or unexported fields
}

func NewTaskQueue

func NewTaskQueue[T any]() *TaskQueue[T]

func (*TaskQueue[T]) ActiveLength

func (tq *TaskQueue[T]) ActiveLength() int

ActiveLength returns the number of non-cancelled tasks in the queue.

func (*TaskQueue[T]) Add

func (tq *TaskQueue[T]) Add(task *Task[T]) error

func (*TaskQueue[T]) CancelTask

func (tq *TaskQueue[T]) CancelTask(taskID string) error

CancelTask cancels a task by its ID. It looks for the task in both queued and running tasks. [NOTE] Cancelled tasks will not be removed from the queue, but marked as cancelled. Use Done to remove them. [WARN] Cancelling a running task relies on the task's implementation to respect the cancellation. If the task does not check for cancellation, it may continue running.

func (*TaskQueue[T]) Close

func (tq *TaskQueue[T]) Close()

func (*TaskQueue[T]) Done

func (tq *TaskQueue[T]) Done(taskID string)

Done stops(cancels) and removes the task from the running tasks.

func (*TaskQueue[T]) Get

func (tq *TaskQueue[T]) Get() (*Task[T], error)

Get retrieves and removes the next non-cancelled task from the queue, adding it to the running tasks. Blocks until a task is available or the queue is closed.

func (*TaskQueue[T]) Length

func (tq *TaskQueue[T]) Length() int

func (*TaskQueue[T]) QueuedTasks added in v0.43.0

func (tq *TaskQueue[T]) QueuedTasks() []TaskInfo

QueuedTasks returns the queued (not yet running) tasks' info. The sorting is in the order of addition.

func (*TaskQueue[T]) RunningTasks added in v0.43.0

func (tq *TaskQueue[T]) RunningTasks() []TaskInfo

RunningTasks returns the currently running tasks' info.

Jump to

Keyboard shortcuts

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