queue

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobQueue

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

JobQueue implements a background job processor using a single channel and wait group.

The channel is initialised with a maximum number of concurrent workers. Adding a new job consumes a worker from the channel. After finishing a job, the worker is added back to the channel. When all workers are consumed, adding new job will block.

Example usage:

jq := NewJobQueue(5)
err := jq.Put(func() error {
	return nil
})
errors.Join(err, jq.Collect())

func NewJobQueue

func NewJobQueue(maxConcurrency uint) *JobQueue

func (*JobQueue) Collect

func (q *JobQueue) Collect() error

Collect waits for all jobs to finish, returning any errors.

func (*JobQueue) Put

func (q *JobQueue) Put(job func() error) error

Put runs a job in the background, returning any error from the previous job.

Jump to

Keyboard shortcuts

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