events

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Complete

func Complete()

Complete stops the event stream, cleaning up its resources using the default subject.

func Next

func Next(topic string, value any, conn ...net.Conn) error

Next emits an event to the given topic using the default subject. If a connection is provided, the event will only be delivered to that specific client.

func Unsubscribe

func Unsubscribe(sub Subscription)

Unsubscribe unsubscribes the given Subscription from its topic using the default subject.

Types

type NextFunc

type NextFunc interface{}

NextFunc is the function called when an event is emitted. It can optionally receive a net.Conn as its last parameter.

type NoOpBroker

type NoOpBroker struct{}

NoOpBroker is a no-op implementation of the pubsub.Broker interface for when NATS is not available

func (*NoOpBroker) CreateStream

func (b *NoOpBroker) CreateStream(streamName, subject string, dedupWindow time.Duration) error

func (*NoOpBroker) Publish

func (b *NoOpBroker) Publish(subject string, message []byte, msgID ...string) error

func (*NoOpBroker) Subscribe

func (b *NoOpBroker) Subscribe(subject string, group string, handler func([]byte) ([]byte, error)) error

type ReplaySubject

type ReplaySubject struct {
	Subject
	// contains filtered or unexported fields
}

ReplaySubject caches the last N events and re-emits them to new subscribers.

func NewReplaySubject

func NewReplaySubject(cacheSize int) *ReplaySubject

NewReplaySubject creates a new ReplaySubject with a specified cache size.

func (*ReplaySubject) Next

func (rs *ReplaySubject) Next(topic string, value any, conn ...net.Conn) error

func (*ReplaySubject) Subscribe

func (rs *ReplaySubject) Subscribe(topic string, next NextFunc, replayEvents bool) Subscription

type Subject

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

func NewSubject

func NewSubject() *Subject

NewSubject creates a new Subject.

func (*Subject) Complete

func (s *Subject) Complete()

func (*Subject) Next

func (s *Subject) Next(topic string, value any, conn ...net.Conn) error

func (*Subject) Subscribe

func (s *Subject) Subscribe(topic string, next NextFunc) Subscription

func (*Subject) Unsubscribe

func (s *Subject) Unsubscribe(sub Subscription)

type Subscription

type Subscription struct {
	Topic     string
	CreatedAt int64
	Next      NextFunc
	ID        string // Add a unique identifier
}

Subscription represents a handler subscribed to a specific topic.

func Subscribe

func Subscribe(topic string, next NextFunc) Subscription

Subscribe subscribes a NextFunc to the given topic using the default subject. A Subscription is returned that can be used to unsubscribe from the topic.

Jump to

Keyboard shortcuts

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