Documentation ¶
Overview ¶
Package watch contains a generic watchable interface, and a fake for testing code that uses the watch interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder interface { // Decode should return the type of event, the decoded object, or an error. // An error will cause StreamWatcher to call Close(). Decode should block until // it has data or an error occurs. Decode() (action EventType, object interface{}, err error) // Close should close the underlying io.Reader, signalling to the source of // the stream that it is no longer being watched. Close() must cause any // outstanding call to Decode() to return with an error of some sort. Close() }
Decoder allows StreamWatcher to watch any stream for which a Decoder can be written.
type Event ¶
type Event struct { Type EventType // If Type == Deleted, then this is the state of the object // immediately before deletion. Object interface{} }
Event represents a single event to a watched resource.
type FakeWatcher ¶
FakeWatcher lets you test anything that consumes a watch.Interface; threadsafe.
func NewFake ¶
func NewFake() *FakeWatcher
func (*FakeWatcher) Action ¶
func (f *FakeWatcher) Action(action EventType, obj interface{})
Action sends an event of the requested type, for table-based testing.
func (*FakeWatcher) Delete ¶
func (f *FakeWatcher) Delete(lastValue interface{})
Delete sends a delete event.
func (*FakeWatcher) Modify ¶
func (f *FakeWatcher) Modify(obj interface{})
Modify sends a modify event.
func (*FakeWatcher) ResultChan ¶
func (f *FakeWatcher) ResultChan() <-chan Event
type FilterFunc ¶
FilterFunc should take an event, possibly modify it in some way, and return the modified event. If the event should be ignored, then return keep=false.
type Interface ¶
type Interface interface { // Stops watching. Will close the channel returned by ResultChan(). Releases // any resources used by the watch. Stop() // Returns a chan which will receive all the events. If an error occurs // or Stop() is called, this channel will be closed, in which case the // watch should be completely cleaned up. ResultChan() <-chan Event }
Interface can be implemented by anything that knows how to watch and report changes.
func Filter ¶
func Filter(w Interface, f FilterFunc) Interface
Filter passes all events through f before allowing them to pass on. Putting a filter on a watch, as an unavoidable side-effect due to the way go channels work, effectively causes the watch's event channel to have its queue length increased by one.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux distributes event notifications among any number of watchers. Every event is delivered to every watcher.
func NewMux ¶
NewMux creates a new Mux. queueLength is the maximum number of events to queue. When queueLength is 0, Action will block until any prior event has been completely distributed. It is guaranteed that events will be distibuted in the order in which they ocurr, but the order in which a single event is distributed among all of the watchers is unspecified.
type StreamWatcher ¶
StreamWatcher turns any stream for which you can write a Decoder interface into a watch.Interface.
func NewStreamWatcher ¶
func NewStreamWatcher(d Decoder) *StreamWatcher
NewStreamWatcher creates a StreamWatcher from the given decoder.
func (*StreamWatcher) ResultChan ¶
func (sw *StreamWatcher) ResultChan() <-chan Event
ResultChan implements Interface.