taskqueue

package
v0.0.0-...-98fa19b Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package taskqueue provides a simple asynchronous task queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger func(v ...any)

Logger provides a way to log panics caused by workers in a queue.

type Option

type Option func(*Queue)

Option defines an option for the queue.

func Depth

func Depth(depth int) Option

Depth sets the depth of the queue. Calls to Submit() will block when this number of tasks are already pending execution. Pass in a negative number to use an unbounded queue. Defaults to unbounded.

func RecoveryHandler

func RecoveryHandler(recoveryHandler errs.RecoveryHandler) Option

RecoveryHandler sets the recovery handler to use for tasks that panic. Defaults to none, which silently ignores the panic.

func Workers

func Workers(workers int) Option

Workers sets the number of workers that will simultaneously process tasks. If this is set to 1, tasks submitted to the queue will be executed serially. Defaults to one plus the number of CPUs.

type Queue

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

Queue holds the queue information.

func New

func New(options ...Option) *Queue

New creates a queue which executes the tasks submitted to it.

func (*Queue) Shutdown

func (q *Queue) Shutdown()

Shutdown the queue. Does not return until all pending tasks have completed.

func (*Queue) Submit

func (q *Queue) Submit(task Task)

Submit a task to be run.

type Task

type Task func()

Task defines a unit of work.

Jump to

Keyboard shortcuts

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