Documentation
¶
Overview ¶
Package namedqueue provides named, typed, bounded in-process queues. Work-sharing queues deliver each message to one of the competing receivers; broadcast queues deliver each message to every subscribed receiver.
Index ¶
- Variables
- func Create[T any](r *QueueRegistry, name string, capacity int) error
- func CreateBroadcasting[T any](r *QueueRegistry, name string, capacity int) error
- func CreateBroadcastingDefault[T any](name string, capacity int) error
- func CreateBroadcastingDefaultWithFullAction[T any](name string, capacity int, action FullAction) error
- func CreateBroadcastingWithFullAction[T any](r *QueueRegistry, name string, capacity int, action FullAction) error
- func CreateDefault[T any](name string, capacity int) error
- func CreateDefaultWithFullAction[T any](name string, capacity int, action FullAction) error
- func CreateWithFullAction[T any](r *QueueRegistry, name string, capacity int, action FullAction) error
- func Destroy(name string) error
- func DestroyTake[T any](r *QueueRegistry, name string) ([]T, error)
- func DestroyTakeDefault[T any](name string) ([]T, error)
- func Shutdown(name string) error
- type FullAction
- type QueueRegistry
- type Receiver
- type Sender
- type State
Constants ¶
This section is empty.
Variables ¶
var ( ErrExists = errors.New("namedqueue: queue already exists") ErrNotFound = errors.New("namedqueue: queue not found") ErrTypeMismatch = errors.New("namedqueue: message type mismatch") ErrClosed = errors.New("namedqueue: queue is closed") ErrFull = errors.New("namedqueue: queue is full") ErrEmpty = errors.New("namedqueue: queue is empty") ErrInvalidCapacity = errors.New("namedqueue: capacity must be positive") ErrInvalidFullAction = errors.New("namedqueue: invalid full action") )
Functions ¶
func Create ¶
func Create[T any](r *QueueRegistry, name string, capacity int) error
Create registers a bounded queue. Capacity must be positive.
func CreateBroadcasting ¶
func CreateBroadcasting[T any](r *QueueRegistry, name string, capacity int) error
CreateBroadcasting registers a bounded queue where every subscribed receiver gets each message independently.
func CreateBroadcastingDefaultWithFullAction ¶
func CreateBroadcastingDefaultWithFullAction[T any](name string, capacity int, action FullAction) error
func CreateBroadcastingWithFullAction ¶
func CreateBroadcastingWithFullAction[T any](r *QueueRegistry, name string, capacity int, action FullAction) error
CreateBroadcastingWithFullAction registers a broadcast queue with a full policy.
func CreateDefaultWithFullAction ¶
func CreateDefaultWithFullAction[T any](name string, capacity int, action FullAction) error
func CreateWithFullAction ¶
func CreateWithFullAction[T any](r *QueueRegistry, name string, capacity int, action FullAction) error
CreateWithFullAction registers a bounded work-sharing queue with a full policy.
func DestroyTake ¶
func DestroyTake[T any](r *QueueRegistry, name string) ([]T, error)
DestroyTake force-retires a queue, returning all still-pending messages.
func DestroyTakeDefault ¶
Types ¶
type FullAction ¶
type FullAction uint8
FullAction selects what Send does when a bounded queue is full.
const ( // FullBlock waits until receivers make space. FullBlock FullAction = iota // FullDropOldest evicts the oldest pending message and enqueues the new one. FullDropOldest // FullDropNewest discards the message being sent and returns success. FullDropNewest )
type QueueRegistry ¶
type QueueRegistry struct {
// contains filtered or unexported fields
}
QueueRegistry owns named queues. Its zero value is ready to use; handles made with Clone share the same registry. Always pass a *QueueRegistry around; a QueueRegistry value must not be copied.
func DefaultRegistry ¶
func DefaultRegistry() *QueueRegistry
func NewRegistry ¶
func NewRegistry() *QueueRegistry
func (*QueueRegistry) Clone ¶
func (r *QueueRegistry) Clone() *QueueRegistry
Clone returns another registry handle sharing the same queues.
func (*QueueRegistry) Destroy ¶
func (r *QueueRegistry) Destroy(name string) error
Destroy force-retires a queue and discards pending messages.
func (*QueueRegistry) Shutdown ¶
func (r *QueueRegistry) Shutdown(name string) error
Shutdown rejects future sends and allows receivers to drain pending messages. Shutting down a queue that is already shut down returns ErrClosed.
type Receiver ¶
type Receiver[T any] struct { // contains filtered or unexported fields }
Receiver is a consumer handle. Copies compete for messages.
func AcquireReceiver ¶
func AcquireReceiver[T any](r *QueueRegistry, name string) (*Receiver[T], error)
AcquireReceiver returns a consumer handle for a registered queue. A shut-down work-sharing queue still admits receivers while messages remain to be drained; a shut-down broadcast queue admits none.
type Sender ¶
type Sender[T any] struct { // contains filtered or unexported fields }
Sender is a producer handle. Copies of a sender share the same queue.
func AcquireSender ¶
func AcquireSender[T any](r *QueueRegistry, name string) (*Sender[T], error)
AcquireSender returns a producer handle for a registered queue. A shut-down queue issues no new senders.