queue

package
v1.207.9 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 2 Imported by: 0

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