Skip to content

Commit 73ebfa7

Browse files
TexasCodingclaude
andcommitted
fix: restore missing _trigger_callbacks method in EventHandlingMixin
The _trigger_callbacks method was accidentally removed during the type error fixes, causing "AttributeError: 'ProjectXRealtimeClient' object has no attribute '_trigger_callbacks'" errors during real-time event processing. This commit restores the method implementation that: - Triggers all registered callbacks for an event type - Handles both async and sync callbacks properly - Includes proper error handling for callback exceptions - Executes callbacks in registration order The method is required by the EventHandlingProtocol and is called by _schedule_async_task when processing real-time events from SignalR. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b6ecfaf commit 73ebfa7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/project_x_py/realtime/event_handling.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,38 @@ async def remove_callback(
211211
self.callbacks[event_type].remove(callback)
212212
self.logger.debug(f"Removed callback for {event_type}")
213213

214+
async def _trigger_callbacks(self, event_type: str, data: dict[str, Any]) -> None:
215+
"""
216+
Trigger all registered callbacks for an event type.
217+
218+
Internal method to execute all callbacks registered for a specific event type.
219+
Handles both async and sync callbacks, with proper error handling.
220+
221+
Args:
222+
event_type: The type of event to trigger callbacks for
223+
data: Event data to pass to callbacks
224+
225+
Note:
226+
- Callbacks are executed in registration order
227+
- Exceptions in callbacks are caught and logged
228+
- Does not block on individual callback failures
229+
"""
230+
if event_type not in self.callbacks:
231+
return
232+
233+
# Get callbacks under lock but execute outside
234+
async with self._callback_lock:
235+
callbacks_to_run = list(self.callbacks[event_type])
236+
237+
for callback in callbacks_to_run:
238+
try:
239+
if asyncio.iscoroutinefunction(callback):
240+
await callback(data)
241+
else:
242+
callback(data)
243+
except Exception as e:
244+
self.logger.error(f"Error in {event_type} callback: {e}", exc_info=True)
245+
214246
# Event forwarding methods (cross-thread safe)
215247
def _forward_account_update(self, *args: Any) -> None:
216248
"""

0 commit comments

Comments
 (0)