diff --git a/ably/executer/eventloop.py b/ably/executer/eventloop.py index 1fbec55d..333092c1 100644 --- a/ably/executer/eventloop.py +++ b/ably/executer/eventloop.py @@ -37,7 +37,7 @@ def loop(self): return self.__loop def run_sync(self, coro): - return LoopHelper.force_sync(self.loop, coro) + return LoopHelper.run_safe_sync(self.loop, coro) def run_async(self, coro): return LoopHelper.run_safe_async(self.loop, coro) diff --git a/ably/executer/eventloop_helper.py b/ably/executer/eventloop_helper.py index 89937cc9..92bc811b 100644 --- a/ably/executer/eventloop_helper.py +++ b/ably/executer/eventloop_helper.py @@ -13,7 +13,7 @@ def run_safe(loop: events, coro, callback): # @staticmethod - def force_sync(loop: events, coro): + def run_safe_sync(loop: events, coro): # Handle result of the given async method, with blocking behaviour caller_eventloop = None try: diff --git a/test/ably/decorator.py b/test/ably/decorator.py index 7b756bb5..29374e3c 100644 --- a/test/ably/decorator.py +++ b/test/ably/decorator.py @@ -14,22 +14,7 @@ def force_sync(fn): @functools.wraps(fn) def wrapper(*args, **kwargs): - caller_eventloop = None - try: - caller_eventloop: events = asyncio.get_running_loop() - except Exception: - pass - app_loop: events = AppEventLoop.get_global().loop - - res = fn(*args, **kwargs) - if asyncio.iscoroutine(res): - # Handle calls from app eventloop on the same loop, return awaitable - if caller_eventloop is not None and caller_eventloop == app_loop: - return res - - # Block the caller till result is returned - future = asyncio.run_coroutine_threadsafe(res, app_loop) - return future.result() - return res + app_loop: events = AppEventLoop.get_global() + return app_loop.run_sync(fn(*args, **kwargs)) return wrapper