Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cancelable ¶
type Cancelable interface {
// Cancel will cancel this object.s
Cancel()
}
Cancelable is an object which can be cancelled.
type Event ¶
type Event[T any] interface { // Add adds a observer to this event. Add(observer Observer[T]) bool // Remove removes the given observer. Remove(observer Observer[T]) bool // Clear removes all the observers from this event. Clear() // Invoke will use the given value to update // all the observers attached to this event. Invoke(value T) }
Event is a collection of observers which will invoke on some event occurrence.
type Joinable ¶
type Joinable[T any] interface { // Joined is called by the given event when the observation // has been added to the event. Joined(event Event[T]) }
Joinable is an observer which gets notified when joined to an event.
type Listener ¶
type Listener[T any] interface { Cancelable // Subscribe adds this listener to the given event. Subscribe(event Event[T]) bool // Unsubscribe removes this listener from the given event. Unsubscribe(event Event[T]) bool }
Listener is a specialized observer that keeps track of the events that it is subscribed to, so that it can be cancelled.
When cancelled, this listener will remove itself from all the events it is subscribed to. If an event clears out it's observations, this listener will automatically unsubscribe from that event.
Use with caution since this could hold onto an event while the event holds onto this listener, meaning neither will be garbage collect until they both can be. Be sure to unsubscribe, cancel, or clear the event when done.
type Observer ¶
type Observer[T any] interface { // Update is called when an event this is listening to is invoked. Update(value T) }
Observer is an object that can be added to an event to listen for that event to be invoked. On the event invocation this update will be called.
type Unjoinable ¶
type Unjoinable[T any] interface { // Unjoined is called by the given event when the observation // has been removed from the event. Unjoined(event Event[T]) }
Unjoinable is an observer which gets notified when unjoined from an event.