oqueue

package
v0.13.14 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = fmt.Errorf("queue was closed")

Functions

This section is empty.

Types

type Operation

type Operation interface {
	UserID() string
}

Operation is an operation, that can be added to the oqueue.

type OperationConsumer

type OperationConsumer func(op Operation) error

OperationConsumer is a function, that consumes an operation. The consumer might return an error.

type Queue

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

Queue implements an operation queue.

func NewQueue

func NewQueue() *Queue

NewQueue returns a new queue.

func (*Queue) AddOperation

func (q *Queue) AddOperation(op Operation) error

AddOperation adds an operation to the queue. Returns ErrClosed if the queue was closed.

func (*Queue) AddSubscriber

func (q *Queue) AddSubscriber(consume OperationConsumer, worker int)

func (*Queue) Close

func (q *Queue) Close()

Close closes the the queue and waits for all elements in the queue to be processed.

type Service

type Service interface {
	// AddOperation adds an operation to the queue.
	// It might return an error, if the queue is closed.
	AddOperation(op Operation) error

	// AddSubscriber adds an operation consumer. It gets notified for every
	// operation landing in the queue.
	// If the consumer returns an error, the error gets logged.
	// The amount of worker defines how many operations are to be consumed
	// concurrently.
	AddSubscriber(consume OperationConsumer, worker int)

	// Close closes the queue. When closed the queue no longer accepts
	// operations.
	// It waits for all operations to be processed before returning.
	Close()
}

Service defines an interface for handling an operator queue. It has methods to add and consume operations. All methods should be save for concurrent use. -go:generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/oqueue Service --output=../../internal/mock/oqueue_service.go --package=mock --mock-name=OQueueService

Jump to

Keyboard shortcuts

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