task

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InactiveError = fmt.Errorf("inactive task queue")

Functions

This section is empty.

Types

type TaskQueue

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

A queue for running jobs serially.

func NewTaskQueue

func NewTaskQueue(name string) TaskQueue

func (*TaskQueue) Active

func (q *TaskQueue) Active() bool

func (*TaskQueue) Enqueue

func (q *TaskQueue) Enqueue(fn func() error) chan error

Pushes the specified function onto the task queue. When the job completes, the result is sent over the returned channel

func (*TaskQueue) Run

func (q *TaskQueue) Run(fn func() error) error

Enqueues the specified function and waits for it to complete.

func (*TaskQueue) Start

func (q *TaskQueue) Start(depth int) error

Starts the task queue. A task queue must be started before jobs can be enqueued to it.

func (*TaskQueue) Stop

func (q *TaskQueue) Stop(cause error) error

Stops the task queue. If there are any queued jobs, this causes them to fail with the specified error. The task queue must be started again before it can be reused. This function blocks until the task loop returns, so alling this from within a job results in deadlock. If a job needs to stop the task queue, it should use StopNoWait instead.

func (*TaskQueue) StopNoWait

func (q *TaskQueue) StopNoWait(cause error) error

Stops the task queue. If there are any queued jobs, this causes them to fail with the specified error. The task queue must be started again before it can be reused. If this function returns success, the stop procedure has successfully initiated, but not necessarily completed.

Jump to

Keyboard shortcuts

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