chanutils

package
v0.0.0-...-ee5cf83 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultQueueSize is the default size to use for concurrent queues.
	DefaultQueueSize = 10
)

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type BatchWriter

type BatchWriter[T any] struct {
	// contains filtered or unexported fields
}

BatchWriter manages writing Filters to the DB and tries to batch the writes as much as possible.

func NewBatchWriter

func NewBatchWriter[T any](cfg *BatchWriterConfig[T]) *BatchWriter[T]

NewBatchWriter constructs a new BatchWriter using the given BatchWriterConfig.

func (*BatchWriter[T]) AddItem

func (b *BatchWriter[T]) AddItem(item T)

AddItem adds a given item to the BatchWriter queue.

func (*BatchWriter[T]) Start

func (b *BatchWriter[T]) Start()

Start starts the BatchWriter.

func (*BatchWriter[T]) Stop

func (b *BatchWriter[T]) Stop()

Stop stops the BatchWriter.

type BatchWriterConfig

type BatchWriterConfig[T any] struct {
	// QueueBufferSize sets the buffer size of the output channel of the
	// concurrent queue used by the BatchWriter.
	QueueBufferSize int

	// MaxBatch is the maximum number of filters to be persisted to the DB
	// in one go.
	MaxBatch int

	// DBWritesTickerDuration is the time after receiving a filter that the
	// writer will wait for more filters before writing the current batch
	// to the DB.
	DBWritesTickerDuration time.Duration

	// PutItems will be used by the BatchWriter to persist filters in
	// batches.
	PutItems func(...T) error
}

BatchWriterConfig holds the configuration options for BatchWriter.

type ConcurrentQueue

type ConcurrentQueue[T any] struct {
	// contains filtered or unexported fields
}

ConcurrentQueue is a typed concurrent-safe FIFO queue with unbounded capacity. Clients interact with the queue by pushing items into the in channel and popping items from the out channel. There is a goroutine that manages moving items from the in channel to the out channel in the correct order that must be started by calling Start().

func NewConcurrentQueue

func NewConcurrentQueue[T any](bufferSize int) *ConcurrentQueue[T]

NewConcurrentQueue constructs a ConcurrentQueue. The bufferSize parameter is the capacity of the output channel. When the size of the queue is below this threshold, pushes do not incur the overhead of the less efficient overflow structure.

func (*ConcurrentQueue[T]) ChanIn

func (cq *ConcurrentQueue[T]) ChanIn() chan<- T

ChanIn returns a channel that can be used to push new items into the queue.

func (*ConcurrentQueue[T]) ChanOut

func (cq *ConcurrentQueue[T]) ChanOut() <-chan T

ChanOut returns a channel that can be used to pop items from the queue.

func (*ConcurrentQueue[T]) Start

func (cq *ConcurrentQueue[T]) Start()

Start begins a goroutine that manages moving items from the in channel to the out channel. The queue tries to move items directly to the out channel minimize overhead, but if the out channel is full it pushes items to an overflow queue. This must be called before using the queue.

func (*ConcurrentQueue[T]) Stop

func (cq *ConcurrentQueue[T]) Stop()

Stop ends the goroutine that moves items from the in channel to the out channel. This does not clear the queue state, so the queue can be restarted without dropping items.

Jump to

Keyboard shortcuts

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