Merge pull request #45 from daily-co/exception_handling_callbacks
Wait for the callback's result, so exceptions get raised
This commit is contained in:
@@ -81,7 +81,10 @@ class DailyTransportService(BaseTransportService, EventHandler):
|
|||||||
for handler in self._event_handlers[event_name]:
|
for handler in self._event_handlers[event_name]:
|
||||||
if inspect.iscoroutinefunction(handler):
|
if inspect.iscoroutinefunction(handler):
|
||||||
if self._loop:
|
if self._loop:
|
||||||
asyncio.run_coroutine_threadsafe(handler(*args, **kwargs), self._loop)
|
future = asyncio.run_coroutine_threadsafe(handler(*args, **kwargs), self._loop)
|
||||||
|
|
||||||
|
# wait for the coroutine to finish. This will also raise any exceptions raised by the coroutine.
|
||||||
|
future.result()
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"No event loop to run coroutine. In order to use async event handlers, you must run the DailyTransportService in an asyncio event loop.")
|
"No event loop to run coroutine. In order to use async event handlers, you must run the DailyTransportService in an asyncio event loop.")
|
||||||
|
|||||||
Reference in New Issue
Block a user