eventstream

package
v0.0.0-...-36d6306 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamToClient

func StreamToClient[Topic any, Payload any, Response any](
	ctx context.Context,
	streamer SyncStreamer[Topic, Payload],
	filter TopicFilter[Topic],
	convert func([]Payload) *Response,
	send func(*Response) error,
	opts *BulkOptions,
) error

StreamToClient bridges a SyncStreamer to a client sending function. It handles the subscription and the continuous loop. It supports batching events before sending to the client.

Types

type BulkOptions

type BulkOptions struct {
	MaxBatchSize  int
	FlushInterval time.Duration
	Ready         chan<- struct{} // Closed after subscription is active (for test synchronization)
}

BulkOptions configures the batching behavior for StreamToClient.

type Event

type Event[Topic any, Payload any] struct {
	Topic   Topic
	Payload Payload
}

Event is the message delivered to subscribers. It contains the topic metadata alongside the payload so handlers can reason about ordering and provenance.

type SyncStreamer

type SyncStreamer[Topic any, Payload any] interface {
	Publish(topic Topic, payloads ...Payload)

	Subscribe(ctx context.Context, filter TopicFilter[Topic]) (<-chan Event[Topic, Payload], error)

	Shutdown()
}

SyncStreamer defines a generic interface for real-time streaming of domain events. Publishers provide a Topic and Payload when emitting changes. Subscribers specify a filter that decides which topics they are interested in.

type TopicFilter

type TopicFilter[Topic any] func(topic Topic) bool

TopicFilter is used to decide whether a subscriber should receive an event published on the given topic. Returning true delivers the event to the subscriber.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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