workers

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 4 Imported by: 0

README

workers

import "github.com/cognusion/go-jar/workers"

Overview

Index

Package files

work.go workerpool.go

Variables

var (
    // DebugOut is a log.Logger for debug messages
    DebugOut = log.New(io.Discard, "[DEBUG] ", 0)
    // ErrorOut is a log.Logger for error messages
    ErrorOut = log.New(io.Discard, "", 0)
)

type Work

type Work interface {
    Work() any
    Return(any)
}

Work is an interface to allow the abstraction of Work and Return, enabling generic Workers doing blind Work

type WorkError

type WorkError struct {
    Messages string
}

WorkError is sent to Work.Return() if the Work generates a panic

func (*WorkError) Error
func (w *WorkError) Error() string

type WorkerPool

type WorkerPool struct {
    // WorkChan is where the work goes
    WorkChan chan Work
    // Stop permanently stops the pool after current work is done.
    // WorkChan is not closed, to prevent errant reads
    Stop func()

    Metrics metrics.Meter
    // contains filtered or unexported fields
}

WorkerPool is a simple mechanation to manage and accomplish Work.

func NewSimpleWorkerPool
func NewSimpleWorkerPool(WorkChan chan Work) *WorkerPool

NewSimpleWorkerPool returns a functioning WorkerPool bound to WorkChan, that does not try keep Workers running. It is strongly recommended that WorkChan be unbounded unless you demonstrably need to bound it.

func (*WorkerPool) AddWork
func (p *WorkerPool) AddWork(work Work)

AddWork adds Work and updates metrics. Will panic if WorkChan is closed.

func (*WorkerPool) Work
func (p *WorkerPool) Work() int

Work returns the quantity of Work in the work channel


Generated by godoc2md

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DebugOut is a log.Logger for debug messages
	DebugOut = log.New(io.Discard, "[DEBUG] ", 0)
	// ErrorOut is a log.Logger for error messages
	ErrorOut = log.New(io.Discard, "", 0)
)

Functions

This section is empty.

Types

type Work

type Work interface {
	Work() any
	Return(any)
}

Work is an interface to allow the abstraction of Work and Return, enabling generic Workers doing blind Work

type WorkError

type WorkError struct {
	Messages string
}

WorkError is sent to Work.Return() if the Work generates a panic

func (*WorkError) Error

func (w *WorkError) Error() string

type WorkerPool

type WorkerPool struct {
	// WorkChan is where the work goes
	WorkChan chan Work
	// Stop permanently stops the pool after current work is done.
	// WorkChan is not closed, to prevent errant reads
	Stop func()

	Metrics metrics.Meter
	// contains filtered or unexported fields
}

WorkerPool is a simple mechanation to manage and accomplish Work.

func NewSimpleWorkerPool added in v1.6.0

func NewSimpleWorkerPool(WorkChan chan Work) *WorkerPool

NewSimpleWorkerPool returns a functioning WorkerPool bound to WorkChan, that does not try keep Workers running. It is strongly recommended that WorkChan be unbounded unless you demonstrably need to bound it.

func (*WorkerPool) AddWork added in v1.6.0

func (p *WorkerPool) AddWork(work Work)

AddWork adds Work and updates metrics. Will panic if WorkChan is closed.

func (*WorkerPool) Work

func (p *WorkerPool) Work() int

Work returns the quantity of Work in the work channel

Jump to

Keyboard shortcuts

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