bus
dev_tool.event.bus
Event
dataclass
A data class representing an event in the system.
This class contains all the information about an event including its type, data, timing, and tracking information.
type
instance-attribute
data
instance-attribute
timestamp
instance-attribute
source
instance-attribute
correlation_id
instance-attribute
EventHandler
Bases: Protocol
A protocol for event handlers.
This class defines the interface that all event handlers must implement to process events from the event bus.
EventBus
A singleton event bus class for publishing and subscribing to events.
This class provides a centralized mechanism for event-driven communication throughout the application with thread-safe operations.
The constructor for the EventBus class.
Initializes the event bus with empty handlers and thread safety locks.
Source code in dev_tool/event/bus.py
lock = threading.RLock()
instance-attribute
__new__
A class method that ensures singleton instance creation with thread safety.
Returns:
-
Self–The singleton EventBus instance.
Source code in dev_tool/event/bus.py
emit
A method that emits an event to all registered handlers.
Parameters:
-
event_type(EventType) –The type of event to emit.
-
data(dict[str, str | int | bool]) –The event data dictionary.
-
source(str, default:'unknown') –The source identifier for the event.
-
correlation_id(str | None, default:None) –Optional correlation ID for event tracking.
Source code in dev_tool/event/bus.py
publish
A method that publishes an event to all registered handlers.
Parameters:
-
event(Event) –The event object to publish to handlers.
Source code in dev_tool/event/bus.py
subscribe
A method that subscribes a handler to a specific event type.
Parameters:
-
event_type(EventType) –The type of event to subscribe to.
-
handler(EventHandler) –The event handler to register for the event type.
Source code in dev_tool/event/bus.py
unsubscribe
A method that unsubscribes a handler from a specific event type.
Parameters:
-
event_type(EventType) –The type of event to unsubscribe from.
-
handler(EventHandler) –The event handler to remove from the event type.