tasks

package
v0.6.16 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WorkerPool

func WorkerPool(ctx context.Context, n int, continueOnError bool) (chan<- Task, func() error)

WorkerPool creates a waitgroup and a taskQueue for a worker pool. It will create "n" workers which will listen for Tasks on the taskQueue. The return value is the taskQueue and a wait function. Do not directly close the taskQueue, use the wait function. Clients should add new tasks to this taskQueue and call the wait function when done. If a worker fails with an error and continueOnError is false, the task context will be canceled, instructing the queue and workers to terminate. Tasks should check ctx as appropriate. The first error encountered will be returned from the wait function and all errors are logged at Warn level.

func WorkerPoolIgnoreError added in v0.6.9

func WorkerPoolIgnoreError(ctx context.Context, n int) (chan<- Task, func())

WorkerPoolIgnoreError instantiates a WorkerPool with continueOnError=true and returns a wait function that captures and logs the error at Error level. This is convenient for defer.

Types

type Task

type Task interface {
	Run(ctx context.Context) error
	String() string
}

Task is a generic interface for a runnable operation

Jump to

Keyboard shortcuts

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