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 ¶
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 ¶
CurrentSeq is the sequence number of the last published event, 0 before any.
func (*Hub) Publish ¶
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.