Dispatches events to registered listeners.
Used for in-transaction (in-process) event processing.
Source code in event_sourcery/_event_store/subscription/in_transaction.py
| class Dispatcher:
"""
Dispatches events to registered listeners.
Used for in-transaction (in-process) event processing.
"""
def __init__(self, serde: Serde, listeners: Listeners) -> None:
self._serde = serde
self._listeners = listeners
def dispatch(self, *raws: RecordedRaw) -> None:
"""
Dispatches one or more raw event records to all registered listeners.
Args:
*raws (RecordedRaw): One or more events to dispatch.
"""
for raw in raws:
record = self._serde.deserialize_record(raw)
event_type = record.wrapped_event.event.__class__
for listener in self._listeners[event_type]:
listener(
record.wrapped_event,
record.stream_id,
record.tenant_id,
record.position,
)
|
dispatch(*raws)
Dispatches one or more raw event records to all registered listeners.
Parameters:
| Name |
Type |
Description |
Default |
*raws |
RecordedRaw
|
One or more events to dispatch.
|
()
|
Source code in event_sourcery/_event_store/subscription/in_transaction.py
| def dispatch(self, *raws: RecordedRaw) -> None:
"""
Dispatches one or more raw event records to all registered listeners.
Args:
*raws (RecordedRaw): One or more events to dispatch.
"""
for raw in raws:
record = self._serde.deserialize_record(raw)
event_type = record.wrapped_event.event.__class__
for listener in self._listeners[event_type]:
listener(
record.wrapped_event,
record.stream_id,
record.tenant_id,
record.position,
)
|