mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
Merge pull request #60 from agessaman/fix-sync-callbacks
Fix: Sync callbacks called inline in `_process_events` to eliminate `no_event_received` race
This commit is contained in:
commit
2c259b9743
1 changed files with 10 additions and 2 deletions
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue