Documentation
¶
Overview ¶
Package autoupdate allows clients to request keys and get updates when the keys changes.
To register to the autoupdate serive, a client has to receive a connection object by calling the Connect()-method. It is not necessary and therefore not possible to close a connection. The client can just stop listening.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Autoupdate ¶
type Autoupdate struct {
// contains filtered or unexported fields
}
Autoupdate holds the state of the autoupdate service. It has to be initialized with autoupdate.New().
func New ¶
func New(datastore Datastore, restricter RestrictMiddleware, voteAddr string, closed <-chan struct{}) *Autoupdate
New creates a new autoupdate service.
The attribute closed is a channel that should be closed when the server shuts down. In this case, all connections get closed.
func (*Autoupdate) Connect ¶
func (a *Autoupdate) Connect(userID int, kb KeysBuilder) DataProvider
Connect has to be called by a client to register to the service. The method returns a Connection object, that can be used to receive the data.
There is no need to "close" the Connection object.
func (*Autoupdate) LastID ¶
func (a *Autoupdate) LastID() uint64
LastID returns the id of the last data update.
func (*Autoupdate) PruneOldData ¶
func (a *Autoupdate) PruneOldData(ctx context.Context)
PruneOldData removes old data from the topic. Blocks until the service is closed.
func (*Autoupdate) ResetCache ¶
func (a *Autoupdate) ResetCache(ctx context.Context)
ResetCache runs in the background and cleans the cache from time to time. Blocks until the service is closed.
type DataProvider ¶
DataProvider is a function that returns the next data for a user.
type Datastore ¶
type Datastore interface { Get(ctx context.Context, keys ...string) (map[string][]byte, error) RegisterChangeListener(f func(map[string][]byte) error) ResetCache() RegisterCalculatedField(field string, f func(ctx context.Context, key string, changed map[string][]byte) ([]byte, error)) RequestKeys(url string, keys []string) (map[string][]byte, error) }
Datastore gets values for keys and informs, if they change.