EventEmitter
class¶
A class that orchestrates the emission of events.
Notes:
-
This class provides a mechanism for emitting and propagating events to subscribers. It is designed to handle
string-named
events with positional and keyword arguments, as well as instances ofdataclass
objects andException
objects. -
This class focuses only on the event emission logic, while the event linker class manages the linkage of events and their responses, and the event processor (a.k.a. processing service) executes the event propagation.
Source code in pyventus/events/emitters/event_emitter.py
19 20 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 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 167 168 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 |
|
Classes¶
EventEmission
¶
Represents an event emission that has been triggered but whose propagation is not yet complete.
This class provides a self-contained context for executing the event emission, encapsulating both the
event data and the associated subscribers. It acts as an isolated unit of work to asynchronously propagate
the emission of an event. When an event occurs, the EventEmitter
class creates an EventEmission
instance, which is then processed by the event processor to handle the event propagation.
Source code in pyventus/events/emitters/event_emitter.py
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 |
|
Attributes¶
id
property
¶
Retrieve the unique identifier of the event emission.
RETURNS | DESCRIPTION |
---|---|
str
|
The unique identifier of the event emission. |
event
property
¶
Retrieve the name of the emitted event.
RETURNS | DESCRIPTION |
---|---|
str
|
The name of the event. |
timestamp
property
¶
Retrieve the timestamp when the event emission was created.
RETURNS | DESCRIPTION |
---|---|
datetime
|
The timestamp when the event emission was created. |
Functions¶
__init__
¶
__init__(event: str, subscribers: set[EventSubscriber], args: tuple[Any, ...], kwargs: dict[str, Any], debug: bool) -> None
Initialize an instance of EventEmission
.
PARAMETER | DESCRIPTION |
---|---|
event
|
The name of the event being emitted.
TYPE:
|
subscribers
|
A set of subscribers associated with the event.
TYPE:
|
args
|
Positional arguments containing event-specific data.
TYPE:
|
kwargs
|
Keyword arguments containing event-specific data.
TYPE:
|
debug
|
Indicates whether debug mode is enabled.
TYPE:
|
Source code in pyventus/events/emitters/event_emitter.py
__call__
async
¶
Execute the subscribers concurrently.
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
Source code in pyventus/events/emitters/event_emitter.py
Functions¶
__init__
¶
__init__(event_processor: ProcessingService, event_linker: type[EventLinker] = EventLinker, debug: bool | None = None) -> None
Initialize an instance of EventEmitter
.
PARAMETER | DESCRIPTION |
---|---|
event_processor
|
The processing service object used to handle the event propagation.
TYPE:
|
event_linker
|
Specifies the type of event linker used to manage and access events along with their corresponding subscribers. Defaults to
TYPE:
|
debug
|
Specifies the debug mode for the logger. If
TYPE:
|
RAISES | DESCRIPTION |
---|---|
PyventusException
|
If the |
Source code in pyventus/events/emitters/event_emitter.py
emit
¶
Emit an event and notifies all registered subscribers.
Notes:
-
When emitting
dataclass
objects orException
objects, they are automatically passed to the subscribers as the first positional argument, even if you pass additional*args
or**kwargs
. -
If there are subscribers registered to the global event
...
(also known asEllipsis
), they will be notified each time an event is emitted.
PARAMETER | DESCRIPTION |
---|---|
event
|
The event to be emitted. It can be
TYPE:
|
args
|
Positional arguments containing event-specific data.
TYPE:
|
kwargs
|
Keyword arguments containing event-specific data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |