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 ¶
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 ¶
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.