Skip to content

Commit

Permalink
Added documentation to the sync decorator method
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 29, 2023
1 parent c6d99a4 commit f81bae4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ably/decorator/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ def wrapper(*args, **kwargs):
except:
pass
ably_eventloop = get_custom_event_loop()

# Handle calls from ably_eventloop on the same loop, return awaitable
if caller_eventloop is not None and caller_eventloop == ably_eventloop:
return ably_eventloop.create_task(fn(*args, **kwargs))

# Post external calls on ably_eventloop, return awaitable on calling eventloop
future = asyncio.run_coroutine_threadsafe(fn(*args, **kwargs), ably_eventloop)
if caller_eventloop is not None and caller_eventloop.is_running():
return asyncio.wrap_future(future)

# If called from regular function instead of coroutine, block till result is available
return future.result()

return wrapper

0 comments on commit f81bae4

Please sign in to comment.