stream

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-2-Clause Imports: 1 Imported by: ? 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 stream carries indexed vault changes from the index to local consumers. It is the local, broker-free counterpart of the Kafka change-event publisher: the same change is announced here as a row delta, so a browser can patch one card instead of reloading a view.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Seq     uint64 `json:"seq"`
	Vault   string `json:"vault"`
	Kind    string `json:"kind"`
	ID      string `json:"id"`
	Path    string `json:"path"`
	Deleted bool   `json:"deleted"`
	Item    any    `json:"item,omitempty"`
}

Event is one indexed change: a row was created or updated (Deleted false), or removed (Deleted true). Seq is assigned by the Hub on publish and increases by one per event, so a consumer that sees a gap knows it missed events and must resync rather than apply a partial stream.

type Hub

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

Hub is the in-process fan-out. It keeps the last capacity events so a reconnecting consumer can catch up from a sequence number, and broadcasts each new event to every subscriber. A subscriber that falls behind loses events; the gap is visible in Seq, which is what tells its consumer to resync.

func NewHub

func NewHub(capacity int) *Hub

NewHub creates a hub that remembers the last capacity events. A capacity <= 0 falls back to 4096, which is far more than a reconnect needs and still small enough that the buffer costs a few hundred kilobytes.

func (*Hub) CurrentSeq

func (h *Hub) CurrentSeq() uint64

CurrentSeq is the sequence number of the last published event, 0 before any.

func (*Hub) Publish

func (h *Hub) Publish(ev Event) uint64

Publish assigns the next sequence number, records the event in the catch-up buffer and broadcasts it. It never blocks: a subscriber whose buffer is full drops this event, and the gap in Seq is what makes it resync.

func (*Hub) Subscribe

func (h *Hub) Subscribe(
	since uint64,
) (replay []Event, ch <-chan Event, cancel func(), truncated bool)

Subscribe returns every buffered event after since, a channel for live events, a cancel function and whether the buffer no longer reaches back to since. When truncated is true the caller must send a resync instead of replaying the partial buffer: applying the surviving tail after a gap would leave the consumer's model silently missing the events the buffer dropped.

since may legitimately be ahead of the hub — a consumer holding a sequence number from before a process restart. That is also a resync, never a wait for numbers that will never be published.

type Sink

type Sink interface {
	Publish(Event) uint64
}

Sink is what the index calls after a change has been applied. It exists so the index depends on a one-method interface rather than on the Hub, which keeps the index testable with a recording fake.

Jump to

Keyboard shortcuts

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