Skip to content

Commit f1dda5f

Browse files
author
Dylan Huang
committed
Add subscription and event handling methods to LazyEventBus
This fixed code from not starting event bus listening loop - Introduced `subscribe`, `unsubscribe`, `emit`, `start_listening`, and `stop_listening` methods to the _LazyEventBus class. - Enhanced type hinting for better code clarity and usability.
1 parent 478c3aa commit f1dda5f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

eval_protocol/event_bus/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Global event bus instance - uses SqliteEventBus for cross-process functionality
2+
from typing import Any, Callable
23
from eval_protocol.event_bus.event_bus import EventBus
34

45

@@ -18,8 +19,20 @@ def _get_event_bus(self):
1819
self._event_bus = _get_default_event_bus()
1920
return self._event_bus
2021

21-
def __getattr__(self, name):
22-
return getattr(self._get_event_bus(), name)
22+
def subscribe(self, callback: Callable[[str, Any], None]) -> None:
23+
return self._get_event_bus().subscribe(callback)
24+
25+
def unsubscribe(self, callback: Callable[[str, Any], None]) -> None:
26+
return self._get_event_bus().unsubscribe(callback)
27+
28+
def emit(self, event_type: str, data: Any) -> None:
29+
return self._get_event_bus().emit(event_type, data)
30+
31+
def start_listening(self) -> None:
32+
return self._get_event_bus().start_listening()
33+
34+
def stop_listening(self) -> None:
35+
return self._get_event_bus().stop_listening()
2336

2437

2538
event_bus: EventBus = _LazyEventBus()

0 commit comments

Comments
 (0)