Documentation ¶
Overview ¶
Package observer aims to simplify the problem of channel-based broadcasting of events from one or more publishers to one or more observers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Property ¶
type Property interface { // Value returns the current value for this property. Value() interface{} // Update sets a new value for this property. Update(value interface{}) // Observe returns a newly created Stream for this property. Observe() Stream }
Property is an object that is continuously updated by one or more publishers. It is completely goroutine safe: you can use Property concurrently from multiple goroutines.
func NewProperty ¶
func NewProperty(value interface{}) Property
NewProperty creates a new Property with the initial value value. It returns the created Property.
type Stream ¶
type Stream interface { // Value returns the current value for this stream. Value() interface{} // Changes returns the channel that is closed when a new value is available. Changes() chan struct{} // Next advances this stream to the next state. // You should never call this unless Changes channel is closed. Next() interface{} // HasNext checks whether there is a new value available. HasNext() bool // WaitNext waits for Changes to be closed, advances the stream and returns // the current value. WaitNext() interface{} // Clone creates a new independent stream from this one but sharing the same // Property. Updates to the property will be reflected in both streams but // they may have different values depending on when they advance the stream // with Next. Clone() Stream }
Stream represents the list of values a property is updated to. For every property update, that value is appended to the list in the order they happen. The value is discarded once you advance the stream. Please note that Stream is not goroutine safe: you cannot use the same stream on multiple goroutines concurrently. If you want to use multiple streams for the same property, either use Property.Observe (goroutine-safe) or use Stream.Clone (before passing it to another goroutine).