API

API#

async awaitlet.async_def(fn: Callable[[...], _T], *args: Any, assert_await_occurs: bool = False, **kwargs: Any) _T#

Runs a sync function fn in a new greenlet.

The sync function can then use awaitlet() to wait for async functions.

Parameters:
  • fn – The sync callable to call.

  • *args – Positional arguments to pass to the fn callable.

  • **kwargs – Keyword arguments to pass to the fn callable.

awaitlet.awaitlet(awaitable: Awaitable[_T]) _T#

Awaits an async function in a sync method.

The sync method must be inside a async_def() context. awaitlet() calls cannot be nested.

Parameters:

awaitable – The coroutine to call.