Publish-Subscribe
hololinked.core.eventloop.pubsub.EventBus
Registry of the events Things can push, and fan-out to whoever is listening.
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 108 109 110 111 112 113 114 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 155 156 157 158 159 160 161 162 163 164 165 166 | |
Functions
__init__
register
Register an event specific to Thing instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Event
|
the descriptor the event was declared as |
required |
|
Thing
|
the instance that pushes the event |
required |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
unregister
Unregister an event specific to a Thing instance, so that publishing it raises.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Event
|
the descriptor the event was declared as |
required |
|
Thing
|
the instance that will push the event |
required |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
subscribe
Subscribe to an event with a callback that will be invoked whenever the event is published.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[[Any], None]
|
called synchronously, on whichever thread pushed the event - which is a |
required |
|
str
|
unique identifier of the event to listen for, as |
required |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
unsubscribe
Unsubscribe from an event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[[Any], None]
|
a callback previously given to |
required |
|
str
|
the event it was subscribed to. Unknown events are ignored. |
required |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
publish
Hand one event's payload to its own subscribers, in subscription order.
The lock is held for the whole fan-out, which is what serializes concurrent pushes from
different Thing threads onto each subscriber's wire.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
unique identifier of the event being pushed, as |
required |
|
Any
|
its payload, unencoded |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
if the event is not registered with this bus |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
event_for
The event registered under an identifier.
A subscriber that needs the event itself - to encode its payloads, say - asks for it once, when it subscribes, instead of being handed it with every push.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
unique identifier of the event, as |
required |
Returns:
| Type | Description |
|---|---|
RegisteredEvent
|
the descriptor and the owner registered under that identifier |
Raises:
| Type | Description |
|---|---|
KeyError
|
if no such event is registered with this bus |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
hololinked.core.eventloop.pubsub.EventSubscription
One event's payloads, delivered onto the subscriber's own loop.
Fans out synchronously on whichever thread pushed the event.
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
Attributes
Functions
__init__
__init__(bus: EventBus, unique_identifier: str, loop: AbstractEventLoop | None = None, maxsize: int = 3) -> None
Subscribe to one event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
EventBus
|
the bus to subscribe to |
required |
|
str
|
the event to listen for, as |
required |
|
AbstractEventLoop | None
|
the loop to deliver on. The running one by default. |
None
|
|
int
|
how many payloads to hold before dropping the oldest |
3
|
Raises:
| Type | Description |
|---|---|
KeyError
|
if no such event is registered with the bus |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
receive
async
Wait for the next payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float | None
|
seconds to wait. Waits indefinitely when not given. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
the payload, unencoded. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
if nothing was pushed before the timeout elapsed. |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
encode
Encode one of this event's payloads the way its objekt is registered to be encoded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
a payload from |
required |
Returns:
| Type | Description |
|---|---|
tuple[bytes, str]
|
the encoded body and the content type to declare for it |
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
event_callback_threadsafe
Called on the pushing thread - hand the payload over and get out of the way.
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
unsubscribe
hololinked.core.eventloop.pubsub.RegisteredEvent
Bases: NamedTuple
A registered event, consisting of its descriptor, owner, and unique identifier.
Source code in repo/hololinked/hololinked/core/eventloop/pubsub.py
Attributes
descriptor
instance-attribute
the class level descriptor the event was declared as.