broadcaster

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 15 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 broadcaster listens for the database's notifications, on a channel, and publishes them, as changes, to a go-server broadcaster, so the server's modules, and its clients, which watch the broadcaster, are told of them, with one connection which listens, rather than one each.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	pg.PoolConn
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, pool pg.PoolConn, opts ...Opt) (_ *Manager, err error)

New creates a new manager, which listens for the notifications on its channel when it's run

func (*Manager) Broadcaster added in v1.4.9

func (self *Manager) Broadcaster() *changes.Broadcaster

Broadcaster returns the broadcaster which the changes are published to, which its HTTP handler streams

func (*Manager) Channel

func (self *Manager) Channel() string

Channel returns the channel the manager listens for notifications on

func (*Manager) Listening

func (self *Manager) Listening() bool

Listening reports whether the manager is listening on its channel, so the changes published to it are published to the broadcaster

func (*Manager) Publish

func (self *Manager) Publish(ctx context.Context, change changeschema.Change) (err error)

Publish publishes the change to the manager's channel, as JSON, so every server listening on it publishes it to its broadcaster. Returns ErrBadParameter when the change is larger than a notification can be.

func (*Manager) Run

func (self *Manager) Run(ctx context.Context, logger *slog.Logger) error

Run listens for the notifications on the manager's channel, and publishes each, as a change, to the broadcaster, logging with the logger, until the context is cancelled, and runs the broadcaster, when it's the manager's, so its watches end when it stops. A notification which isn't a change, such as one whose action isn't INSERT, UPDATE or DELETE, is logged, and skipped. When the connection which listens closes, such as when it fails, it listens again, and the notifications in between are missed. When it can't listen again, such as while the database restarts, it logs that, and tries again, after a delay which doubles each time, until it can, or the context is cancelled. When it can't listen at first, it returns the error. Only one can run at a time.

func (*Manager) Running

func (self *Manager) Running() bool

Running reports whether the manager is running

func (*Manager) Schema

func (self *Manager) Schema() string

Schema returns the database schema of the manager

func (*Manager) Shared added in v1.4.9

func (self *Manager) Shared() bool

Shared returns true when the broadcaster is shared with the manager, with WithBroadcaster, so it isn't the manager's, which runs it

func (*Manager) WaitListening

func (self *Manager) WaitListening(ctx context.Context) error

WaitListening waits until the manager is listening on its channel, so the changes made from then are published to the broadcaster, or returns the context's error when it's cancelled first

func (*Manager) Watch added in v1.4.9

func (self *Manager) Watch(ctx context.Context, filter changeschema.ChangeFilter, ch chan<- changeschema.Change) (<-chan error, error)

Watch sends the changes which are published to the broadcaster, and match the filter, to the channel, as the broadcaster's Watch does, until the context is cancelled, or the broadcaster stops running

type Opt

type Opt func(*opt) error

Opt is a functional option for the broadcaster manager's configuration

func WithBroadcaster added in v1.4.9

func WithBroadcaster(broadcaster *changes.Broadcaster) Opt

WithBroadcaster publishes the changes to the broadcaster, which is shared, such as with the server's other modules, which publish theirs to it, so their clients watch one stream of changes. A shared broadcaster isn't run by the manager, but by whatever shares it.

func WithChannel

func WithChannel(channel string) Opt

WithChannel sets the channel the notifications are listened for on, which must be an identifier

func WithSchema

func WithSchema(name string) Opt

WithSchema sets the database schema, which must be an identifier

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer used for tracing operations

Directories

Path Synopsis
Package cmd has the broadcaster's flags for a server.
Package cmd has the broadcaster's flags for a server.

Jump to

Keyboard shortcuts

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