Documentation
¶
Index ¶
- type Task
- type TaskInfo
- type TaskQueue
- func (tq *TaskQueue[T]) ActiveLength() int
- func (tq *TaskQueue[T]) Add(task *Task[T]) error
- func (tq *TaskQueue[T]) CancelTask(taskID string) error
- func (tq *TaskQueue[T]) Close()
- func (tq *TaskQueue[T]) Done(taskID string)
- func (tq *TaskQueue[T]) Get() (*Task[T], error)
- func (tq *TaskQueue[T]) Length() int
- func (tq *TaskQueue[T]) QueuedTasks() []TaskInfo
- func (tq *TaskQueue[T]) RunningTasks() []TaskInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TaskQueue ¶
type TaskQueue[T any] struct { // contains filtered or unexported fields }
func NewTaskQueue ¶
func (*TaskQueue[T]) ActiveLength ¶
ActiveLength returns the number of non-cancelled tasks in the queue.
func (*TaskQueue[T]) CancelTask ¶
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]) Get ¶
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]) QueuedTasks ¶ added in v0.43.0
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
RunningTasks returns the currently running tasks' info.