event
This module defines all the communications and eventing interfaces for the system.
EventData = TypeVar('EventData')
module-attribute
EventFilter = Callable[[Event[EventData]], bool]
module-attribute
EventListener = Callable[[Event[EventData]], None]
module-attribute
eventbus_names = set()
module-attribute
BusConnection
Bases: Generic[EventData]
A connection between an EventBus and a Component, used to send Events
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Generic
|
EventData
|
The data type that will be sent over this connection |
required |
Source code in roc/event.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
attached_bus = bus
instance-attribute
attached_component = component
instance-attribute
subject = self.attached_bus.subject
instance-attribute
subscribers = []
instance-attribute
__init__(bus, component)
Source code in roc/event.py
66 67 68 69 70 71 |
|
close()
Source code in roc/event.py
101 102 103 104 105 106 107 |
|
listen(listener, *, filter=None)
Source code in roc/event.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
send(data)
Send data over the EventBus. Internally, the data is converted to an Event with the relevant data (such as the source Component).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
EventData
|
The data type of the data to be sent |
required |
Source code in roc/event.py
73 74 75 76 77 78 79 80 81 82 |
|
Event
Bases: ABC
, Generic[EventData]
An abstract event class for sending messages between Components over an EventBus
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ABC
|
ABC
|
Abstract base class |
required |
Generic
|
EventData
|
The data to be carried by the event |
required |
Source code in roc/event.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
bus = bus
instance-attribute
data = data
instance-attribute
src_id = src_id
instance-attribute
__init__(data, src_id, bus)
The initializer for the Event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
EventData
|
The data for this event |
required |
src_id
|
ComponentId
|
The name and type of the Component sending the event |
required |
bus
|
EventBus
|
The EventBus that the event is being sent over |
required |
Source code in roc/event.py
29 30 31 32 33 34 35 36 37 38 39 |
|
__repr__()
Source code in roc/event.py
41 42 43 44 45 46 47 48 49 50 51 52 |
|
EventBus
Bases: Generic[EventData]
A communication channel for sending events between Components
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Generic
|
EventData
|
The data type that is allowed to be sent over the bus |
required |
Source code in roc/event.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
cache = None
instance-attribute
cache_depth = cache_depth
instance-attribute
name = name
instance-attribute
The name of the bus. Used to ensure uniqueness.
subject = rx.Subject[Event[EventData]]()
instance-attribute
The RxPy Subject that the bus uses to communicate.
__init__(name, cache_depth=0)
Source code in roc/event.py
127 128 129 130 131 132 133 134 135 136 137 138 |
|
clear_names()
staticmethod
Clears all EventBusses that have been registered, mostly used for testing.
Source code in roc/event.py
151 152 153 154 |
|
connect(component)
Creates a connection between an EventBus and a Component for sending Events
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
Component
|
The Component to connect to the bus |
required |
Returns:
Type | Description |
---|---|
BusConnection[EventData]
|
BusConnection[EventData]: A new connection that can be used to send data |
Source code in roc/event.py
140 141 142 143 144 145 146 147 148 149 |
|