Eventbus
EventBus
Event dispatch mechanism for propagating event objects to subscribers.
The event bus maintains subscriptions between subscribers and concrete event types. Events published to the bus are synchronously delivered to all subscribers registered for the exact event type.
Subscription management and event publication are thread-safe. Event delivery itself occurs outside the internal lock.
__init__()
Initialize an empty event bus.
The bus starts with no registered subscribers and no active subscriptions.
Source code in src/onesecondtrader/messaging/eventbus.py
subscribe(subscriber, event_type)
Register a subscriber for a specific event type.
The subscriber will receive all future events whose concrete type matches event_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscriber
|
Subscriber
|
Object receiving published events. |
required |
event_type
|
type[EventBase]
|
Concrete event class the subscriber is interested in. |
required |
Source code in src/onesecondtrader/messaging/eventbus.py
unsubscribe(subscriber)
Remove a subscriber from all event subscriptions.
After unsubscription, the subscriber will no longer receive any events published on this bus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscriber
|
Subscriber
|
Subscriber to remove. |
required |
Source code in src/onesecondtrader/messaging/eventbus.py
publish(event)
Publish an event to all subscribed listeners.
Subscribers are matched strictly by the concrete type of the event. Parent classes and inheritance relationships are not considered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
EventBase
|
Event instance to dispatch. |
required |
Source code in src/onesecondtrader/messaging/eventbus.py
wait_until_system_idle()
Block until all subscribers report an idle state.
This method delegates to each subscriber's wait_until_idle method and returns only after all subscribers have completed any pending work.