mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
modify event callback handling to call synchronous callbacks inline, ensuring futures are resolved before waiting. This prevents race conditions when scheduling callbacks asynchronously.
This commit is contained in:
@@ -183,8 +183,16 @@ class EventDispatcher:
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Fire the call back asychronously
|
# Call sync callbacks inline so futures are resolved before asyncio.wait()
|
||||||
asyncio.create_task(self._execute_callback(subscription.callback, event.clone()))
|
# returns - avoids the race where create_task schedules the callback after
|
||||||
|
# the waiter has already timed out with done=set().
|
||||||
|
if asyncio.iscoroutinefunction(subscription.callback):
|
||||||
|
asyncio.create_task(self._execute_callback(subscription.callback, event.clone()))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
subscription.callback(event.clone())
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in event handler for {event.type}: {e}", exc_info=True)
|
||||||
|
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user