Events#
Events are one of the most flexible ways to send data
between systems and allow systems to communicate with each other.
Any system can publish an event and any system can subscribe to an event.
We send events using EventWriter
and receive events using
EventReader
. Any arbitrary Python type can be used to create
events:
from dataclasses import dataclass
@dataclass
class MyEvent:
message: str
def writer_system(
writer: xx.EventWriter[MyEvent],
) -> None:
writer.send(MyEvent("Boom!"))
def reader_system(
reader: xx.EventReader[MyEvent],
) -> None:
for event in reader.events:
print(event.message)
Boom!
Every system will have access to all the events that have been triggered since the last time that system ran.