pubsub

package
v0.0.0-...-3d597f3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBufferSizeTooLarge = errors.New("buffer size too large")

ErrBufferSizeTooLarge is returned when the buffer size for a topic exceeds the maximum allowed size as defined in the runtime options.

View Source
var ErrInvalidTopicName = errors.New("invalid topic name")

ErrInvalidTopicName is returned when a topic name is invalid.

View Source
var ErrTopicClosed = errors.New("topic is closed")

ErrTopicClosed is returned when publishing to a closed topic.

Functions

This section is empty.

Types

type PubSub

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

func New

func New(logger *slog.Logger, rt privApi.Runtime) *PubSub

func (*PubSub) Close

func (h *PubSub) Close()

Close closes all topics and their subscriptions.

func (*PubSub) CreateTopic

func (h *PubSub) CreateTopic(name string, bufferSize uint32) error

CreateTopic creates a new topic with the given name and buffer size. Returns an error if the topic already exists or if the buffer size exceeds the maximum allowed size.

func (*PubSub) Publish

func (h *PubSub) Publish(ctx context.Context, topicName string, msg any) error

Publish sends an event to the given topic. Returns an error if the topic does not exist or if publishing fails.

func (*PubSub) Subscribe

func (h *PubSub) Subscribe(topicName, subscription string) (api.SubscriptionHandle, error)

Subscribe creates or retrieves a subscription to the given topic.

type Subscription

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

A Subscription represents a subscription to a topic. Every message is delivered to every subscription exactly once. Multiple consumers can read from the same subscription's Data() channel.

func (*Subscription) Close

func (s *Subscription) Close()

Close closes the subscription for every consumer. Safe to call multiple times per subscription (although all subscribers will stop receiving messages once called once).

func (*Subscription) Data

func (s *Subscription) Data() <-chan any

Data returns the channel on which the subscription receives data. Consumers should range over this channel to receive messages. The channel is closed when the subscription or its associated topic are closed.

Jump to

Keyboard shortcuts

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