room

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MPL-2.0 Imports: 1 Imported by: 1 module, 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 room is an in-process pub/sub for room timelines: the room inlet publishes messages to a (tenant, room); SSE subscribers receive them live, plus a short backfill of recent ones.

Single-node by design — fleet fan-out across chassis nodes is an overlay seam (the NATS feed/trace-subscriber backends), deferred. Durable history is the event/trace log (events-as-history); the ring buffer here is only a live-backfill cache, not the system of record.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Seq       int64  `json:"seq"`
	Room      string `json:"room"`
	Actor     string `json:"actor"`
	Text      string `json:"text"`
	MessageID string `json:"message_id,omitempty"`
}

Event is one message in a room's timeline, as published to subscribers.

type Hub

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

Hub fans out room Events to live subscribers and keeps a small per-room ring buffer of recent Events for subscriber backfill. Safe for concurrent use.

func NewHub

func NewHub(ringSize int) *Hub

NewHub returns a Hub keeping the last ringSize Events per room for backfill (ringSize <= 0 defaults to 50).

func (*Hub) Publish

func (h *Hub) Publish(tenant, room, actor, text, messageID string) Event

Publish appends an Event to (tenant, room): it assigns a per-room sequence, records it in the ring buffer, and fans it out to live subscribers (non-blocking — a subscriber whose buffer is full drops this Event rather than stalling the publisher). Returns the stored Event.

func (*Hub) Subscribe

func (h *Hub) Subscribe(tenant, room string) (<-chan Event, []Event, func())

Subscribe registers a live subscriber for (tenant, room). It returns the live Event channel, a snapshot of the recent ring buffer (oldest first), and an unsubscribe func the caller MUST invoke when done (it removes the subscriber and closes the channel; calling it more than once is safe).

Jump to

Keyboard shortcuts

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