run_sync¶
-
privex.helpers.asyncx.
run_sync
(func, *args, **kwargs)[source]¶ Run an async function synchronously (useful for REPL testing async functions). (TIP: Consider using
loop_run()
instead)Attention
For most cases, you should use the function
loop_run()
instead of this. Unlikerun_sync
,loop_run()
is able to handle async function references, coroutines, as well as coroutines / async functions which are wrapped in an outer non-async function (e.g. an@awaitable
wrapper).loop_run()
also supports using a custom event loop, instead of being limited toasyncio.get_event_loop()
Usage:
>>> async def my_async_func(a, b, x=None, y=None): ... return a, b, x, y >>> >>> run_sync(my_async_func, 1, 2, x=3, y=4) (1, 2, 3, 4,)
- Parameters
func (callable) – An asynchronous function to run
args – Positional arguments to pass to
func
kwargs – Keyword arguments to pass to
func