stream

package
v0.8.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package stream is grain's server->browser push channel. A per-pubkey hub fans live messages (login-hydration live-sync #87, streaming fetch #77) out to a user's open pages over SSE; connections register on connect and drop on disconnect. Lifecycle callbacks let a consumer start work (e.g. the own-event subscription) only while a page is actually open.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

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

Hub fans push messages out to a user's open browser pages, keyed by pubkey.

func Default

func Default() *Hub

Default returns the process-wide hub.

func (*Hub) HasClients

func (h *Hub) HasClients(pubkey string) bool

HasClients reports whether pubkey currently has any open connection.

func (*Hub) Push

func (h *Hub) Push(pubkey string, msg Message)

Push delivers a message to all of pubkey's open connections. Non-blocking: a connection whose buffer is full drops the message rather than stalling others.

func (*Hub) Register

func (h *Hub) Register(pubkey string) (<-chan Message, func())

Register adds a connection for pubkey and returns its message channel plus an unregister func to call on disconnect.

func (*Hub) SetLifecycle

func (h *Hub) SetLifecycle(onFirst, onLast func(string))

SetLifecycle wires callbacks fired when a pubkey gains its first / loses its last open connection — so the live-sync subscription runs only while a page is open. Either may be nil.

type Message

type Message struct {
	Type string `json:"type"`           // "list-updated" | "profile-updated" | ...
	Kind int    `json:"kind,omitempty"` // event kind, when relevant
	Data any    `json:"data,omitempty"` // optional payload
}

Message is a JSON-serialisable push sent to a user's open pages.

Jump to

Keyboard shortcuts

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