memory

package
v0.0.3-beta.9 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MessageQueue

type MessageQueue[T any] struct {
	*Queue[T]
	*PubSub[T]
}

MessageQueue combines both queue and publish-subscribe functionality in a single memory-based implementation. It provides both point-to-point messaging and broadcast messaging capabilities.

func NewMessageQueue

func NewMessageQueue[T any](opt ...Option) *MessageQueue[T]

NewMessageQueue creates a new memory-based message queue that supports both queue and pub/sub operations. The same options apply to both the underlying queue and pub/sub components.

func (*MessageQueue[T]) Close

func (p *MessageQueue[T]) Close() error

type Option

type Option func(*options)

Option defines a function type for configuring memory message queue options.

func WithQueueSize

func WithQueueSize(size int) Option

WithQueueSize sets the buffer size for message channels in the memory queue. A larger size allows more messages to be buffered before blocking publishers.

type PubSub

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

PubSub implements an in-memory publish-subscribe message system with typed message support. It broadcasts messages to all active subscribers of a topic.

func NewPubSub

func NewPubSub[T any](opt ...Option) *PubSub[T]

NewPubSub creates a new memory-based publish-subscribe system with the specified options. The default queue size is 100 messages per subscription.

func (*PubSub[T]) Broadcast

func (p *PubSub[T]) Broadcast(ctx context.Context, topic string, data T) error

func (*PubSub[T]) Close

func (p *PubSub[T]) Close() error

func (*PubSub[T]) Subscribe

func (p *PubSub[T]) Subscribe(ctx context.Context, topic string, handler func(data T) error) error

func (*PubSub[T]) UnsubscribeAll

func (p *PubSub[T]) UnsubscribeAll(ctx context.Context, topic string) error

type Queue

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

Queue implements an in-memory point-to-point message queue with typed message support. It provides FIFO message delivery to exactly one consumer per topic.

func NewQueue

func NewQueue[T any](opt ...Option) *Queue[T]

NewQueue creates a new memory-based queue with the specified options. The default queue size is 100 messages per topic.

func (*Queue[T]) Close

func (q *Queue[T]) Close() error

func (*Queue[T]) Consume

func (q *Queue[T]) Consume(ctx context.Context, topic string) (T, error)

func (*Queue[T]) Publish

func (q *Queue[T]) Publish(ctx context.Context, topic string, data T) error

func (*Queue[T]) PurgeQueue

func (q *Queue[T]) PurgeQueue(ctx context.Context, topic string) error

type Subscription

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

Subscription represents an active subscription to a topic with its associated handler and channels.

Jump to

Keyboard shortcuts

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