msgq

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package msgq implements a simple, finite-sized message queue. It can be used as a building block for a message processor pool.

Index

Constants

This section is empty.

Variables

View Source
var ErrRxOverrun = errors.New("rx overrun")

ErrRxOverrun signals that a receive queue has been overrun.

Functions

This section is empty.

Types

type MessageAdder

type MessageAdder interface {
	AddMessage(content []byte, sender peer.ID) error
}

MessageAdder enqueues a received message for processing. It returns without blocking, and may return a queue overrun error.

type MessageHandler

type MessageHandler interface {
	HandleMessage(content []byte, sender peer.ID)
}

MessageHandler is a message handler.

type Queue

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

Queue is a finite-sized message queue.

func New

func New(size int) *Queue

New returns a new message queue of the given size.

func (*Queue) AddMessage

func (q *Queue) AddMessage(content []byte, sender peer.ID) error

AddMessage enqueues a received message for processing. It returns without blocking, and may return a queue overrun error.

func (*Queue) Close

func (q *Queue) Close() error

Close closes the given queue.

func (*Queue) HandleMessages

func (q *Queue) HandleMessages(h MessageHandler)

HandleMessages dequeues and dispatches incoming messages using the given message handler, until the message queue is closed. This function can be spawned as a background goroutine, potentially multiple times for a pool.

Jump to

Keyboard shortcuts

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