events

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events fans committed events out to subscribed connections and replays the durable log for subscribers that resume (docs/specs/rpc-protocol.md).

Index

Constants

View Source
const Buffer = 1024

Buffer is how many undelivered events a subscription holds before the broker drops it as lagging; the client reconnects and resumes by seq.

Variables

View Source
var ErrLagged = errors.New("events: subscriber lagged")

ErrLagged ends a subscription whose consumer fell more than Buffer behind.

Functions

This section is empty.

Types

type Broker

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

Broker delivers events to subscriptions. Publish never blocks.

func NewBroker

func NewBroker(log Log) *Broker

NewBroker returns a broker that replays from log.

func (*Broker) Publish

func (b *Broker) Publish(evs []api.EventEnvelope)

Publish delivers events, in order, to every subscription; it is the store's OnCommit hook. A full subscription is dropped with ErrLagged.

func (*Broker) Subscribe

func (b *Broker) Subscribe(ctx context.Context, sinceSeq *int64) (*Subscription, api.Subscription, error)

Subscribe registers a subscription before reading the log, so no event falls between replay and live delivery. With sinceSeq nil it delivers live events only. The result reports resync when sinceSeq is no longer replayable, in which case nothing is replayed.

type Log

type Log interface {
	LatestSeq(ctx context.Context) (int64, error)
	OldestSeq(ctx context.Context) (int64, error)
	ChangesSince(ctx context.Context, seq int64) ([]api.EventEnvelope, error)
}

Log is the durable event log (store.DB implements it).

type Subscription

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

Subscription is one connection's event stream.

func (*Subscription) Close

func (s *Subscription) Close()

Close unregisters the subscription and stops Run.

func (*Subscription) Run

func (s *Subscription) Run(ctx context.Context, send func(api.EventEnvelope) error) error

Run sends the replay, then live events, until ctx ends, the subscription is closed or lags, or send fails. Durable live events already replayed are skipped, so each seq is delivered once and in order.

Jump to

Keyboard shortcuts

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