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 ¶
var RescanInterval = 100 * time.Millisecond
RescanInterval is how often Run sends the rescans which watches are owed, when no changes are published to send them with
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 (*Broadcaster) Flush ¶ added in v1.8.19
func (b *Broadcaster) Flush()
Flush sends the rescans which watches are owed, which their channels can receive now. Run calls it at the RescanInterval, and Publish before each change, so it's only needed by a broadcaster which isn't run.
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, after the rescans it's owed, and returns how many couldn't, as their channels were full, so they missed it, and are owed a rescan of its table, or were owed one already. 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. While it runs, it sends the rescans which watches are owed, at the RescanInterval (see Flush). 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 is owed a rescan of its table: a change of the table's schema and name, which is an update, without a row, so it reads the table again. A rescan is sent before the changes after it, once the channel can receive it, whatever the filter's action. The changes of a table which is owed a rescan aren't sent, as they're in it. A channel 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 |