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 (*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) 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 |