chanqueue

package
v1.2.22 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package chanqueue provides a local queue based on channels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChanQueue

type ChanQueue struct {
	// MaxTimeNoRead is the maximum idle time before stop
	// processing messages.
	MaxTimeNoRead time.Duration
	// contains filtered or unexported fields
}

ChanQueue represents a queue.

func New

func New(proc queue.MessageProcessor) *ChanQueue

New returns a ChanQueue. Messages are processed with proc. If proc is nil, a processor must be set with ChanQueue.SetMessageProcessor before calling ChanQueue.StartReading. Otherwise, ChanQueue.StartReading returns an error and stops reading.

func (*ChanQueue) LastMessageReceived

func (q *ChanQueue) LastMessageReceived() *time.Time

LastMessageReceived returns the time when the last message was read. If no messages have been read it returns nil.

func (*ChanQueue) SetMessageProcessor

func (q *ChanQueue) SetMessageProcessor(proc queue.MessageProcessor)

SetMessageProcessor sets the queue's message processor. It must be set before calling ChanQueue.StartReading.

func (*ChanQueue) StartReading

func (q *ChanQueue) StartReading(ctx context.Context) <-chan error

StartReading starts reading messages from the queue. It reads messages only when there are free tokens in the message processor. It will stop reading from the queue when the provided context is canceled. The caller can use the returned channel to track when the reader stops reading from the queue and all the messages have been processed.

func (*ChanQueue) Write

func (q *ChanQueue) Write(body string) error

Write writes a message with the specified body into the queue.

Jump to

Keyboard shortcuts

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