queue

package
v0.0.0-...-b0bff92 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnqueueTimeout is the timeout for enqueueing an operation. If an
	// operation can't be processed in the time, a ErrDeadlineExceeded is
	// returned.
	EnqueueTimeout time.Duration = time.Second * 3

	// EnqueueBatchSize dictates how many operations can be processed at any
	// one time.
	EnqueueBatchSize = 64
)

Variables

View Source
var (
	// ErrDeadlineExceeded is a sentinel error for all exceeded deadlines for
	// operations.
	ErrDeadlineExceeded = deadlineExceededErr("enqueueing deadline exceeded")

	// ErrCanceled is a sentinel error for when the operation has been stopped.
	ErrCanceled = canceledErr("enqueueing canceled")
)

Functions

func IsCanceled

func IsCanceled(err error) bool

IsCanceled checks to see if the underlying error is a canceled error.

func IsDeadlineExceeded

func IsDeadlineExceeded(err error) bool

IsDeadlineExceeded checks to see if the underlying error is a deadline exceeded error.

Types

type OpQueue

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

OpQueue holds the operations in a blocking queue. The purpose of this queue is to allow the backing off of operations at the source of enqueueing, and not at the consuming of the queue.

func NewOpQueue

func NewOpQueue(clock clock.Clock) *OpQueue

NewOpQueue creates a new OpQueue.

func (*OpQueue) Enqueue

func (q *OpQueue) Enqueue(op Operation)

Enqueue will add an operation to the queue. As this is a blocking queue, any additional enqueue operations will block and wait for subsequent operations to be completed. The design of this is to ensure that people calling this will have to correctly handle backing off from enqueueing.

func (*OpQueue) Kill

func (q *OpQueue) Kill(reason error)

Kill puts the tomb in a dying state for the given reason, closes the Dying channel, and sets Alive to false.

func (*OpQueue) Queue

func (q *OpQueue) Queue() <-chan []Operation

Queue returns the queue of operations. Removing an item from the channel will unblock to allow another to take it's place.

func (*OpQueue) Wait

func (q *OpQueue) Wait() error

Wait blocks until all goroutines have finished running, and then returns the reason for their death.

type Operation

type Operation struct {
	Command []byte
	Done    func(error)
	Stop    func() <-chan struct{}
}

Operation holds the operations that a queue can hold.

Jump to

Keyboard shortcuts

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