bqueue

package
v0.108.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCacheSize = 2000

DefaultCacheSize is the default amount of Queueable elements above the current height which are stored in the queue.

Variables

This section is empty.

Functions

This section is empty.

Types

type Indexable added in v0.108.0

type Indexable interface {
	GetIndex() uint32
}

Indexable is an interface for an element that has an index.

type OperationMode added in v0.107.0

type OperationMode byte

OperationMode is the mode of operation for the queue. Could be either Blocking or NonBlocking.

const (
	// NonBlocking means that Put will return immediately if the queue is full.
	NonBlocking OperationMode = 0
	// Blocking means that Put will wait until there is enough space in the queue.
	Blocking OperationMode = 1
)

type Queue

type Queue[Q Queueable] struct {
	// contains filtered or unexported fields
}

Queue is the queue of queueable elements.

func New

func New[Q Queueable](bc Queuer[Q], log *zap.Logger, relayer func(Q), cacheSize int, lenMetricsUpdater func(l int), mode OperationMode) *Queue[Q]

New creates an instance of Queue that handles Queueable elements.

func (*Queue[Q]) Discard

func (bq *Queue[Q]) Discard()

Discard stops the queue and prevents it from accepting more elements to enqueue.

func (*Queue[Q]) LastQueued

func (bq *Queue[Q]) LastQueued() (uint32, int)

LastQueued returns the index of the last queued element and the queue's capacity left.

func (*Queue[Q]) Put added in v0.108.0

func (bq *Queue[Q]) Put(element Q) error

Put enqueues Queueable element to be added to the chain.

func (*Queue[Q]) Run

func (bq *Queue[Q]) Run()

Run runs the Queue queueing loop. It must be called in a separate routine.

type Queueable added in v0.108.0

type Queueable interface {
	Indexable
	comparable
}

Queueable is an interface for a queue element.

type Queuer added in v0.108.0

type Queuer[Q Queueable] interface {
	AddItem(Q) error
	AddItems(...Q) error
	Height() uint32
}

Queuer is an interface for a queue.

Jump to

Keyboard shortcuts

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