broadcaster

package
v1.8.8 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 5 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 publishes changes, such as to the rows of a server's tables, to the channels which watch it, so a server's clients see the changes as they happen

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

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

Broadcaster sends the changes which are published to each channel which is watching it, whose filter they match. It's watched until it stops running.

func New

func New() *Broadcaster

New returns a broadcaster, which can be watched

func (*Broadcaster) Publish

func (b *Broadcaster) Publish(change schema.Change) int

Publish sends the change to each channel which is watching, whose filter it matches, which can receive it now, and returns how many couldn't, as their channels were full, so they missed it. It never waits, so it can be called under a lock, which keeps the changes in the order they happened.

func (*Broadcaster) Run

func (b *Broadcaster) Run(ctx context.Context) error

Run runs the broadcaster until the context is cancelled, when every watch ends, with ErrServiceUnavailable, as there will be no more events, such as when the server is stopping, and it isn't watched again until it runs again. It returns nil.

func (*Broadcaster) Running added in v1.8.1

func (b *Broadcaster) Running() bool

Running reports whether the broadcaster is running, so it's watched, such as once Run, which is started in a goroutine, has started, and until it stops. A broadcaster which has stopped isn't watched until it's running again. One which has never run is watched, but isn't running.

func (*Broadcaster) Watch

func (b *Broadcaster) Watch(ctx context.Context, filter schema.ChangeFilter, ch chan<- schema.Change) (<-chan error, error)

Watch sends the changes which are published, and match the filter, to the channel, which are all of them when the filter is empty, from when it returns, as it's watching before it does, until the context is cancelled, or the broadcaster stops running, as there will be no more changes.

It returns a channel which is sent nil when the context is cancelled, or ErrServiceUnavailable when the broadcaster stops running, once the watch has ended, after which no more changes are sent to the channel, so it can be closed. A broadcaster which has stopped running isn't watched, and returns ErrServiceUnavailable, until it runs again.

A change isn't waited for the channel to receive, so a channel which is full misses it, and one which needs every change should be buffered. Returns ErrBadRequest when there's no channel, or the filter's action isn't one of the actions, and ErrConflict when the channel is watching already.

Directories

Path Synopsis
Package cmd has the broadcaster's commands and flags
Package cmd has the broadcaster's commands and flags
Package httpclient is a client of the broadcaster's HTTP API
Package httpclient is a client of the broadcaster's HTTP API
Package httphandler has the broadcaster's HTTP API, which streams its changes to clients
Package httphandler has the broadcaster's HTTP API, which streams its changes to clients
Package schema has the changes which a broadcaster publishes
Package schema has the changes which a broadcaster publishes

Jump to

Keyboard shortcuts

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