tff.async_utils.AsyncThreadRunner

Class which bridges async and synchronous synchronous interfaces.

This class serves as a resource and logic container, starting an event loop in a separate thread and managing dispatching of coroutine functions to this event loop in both synchronous and asynchronous interfaces.

There are two main uses of this class. First, this class can be used to wrap interfaces which use asyncio in a synchronous 'run this coroutine' interface in a manner which is compatible with integrating with other async libraries. This feature is generally useful for backwards-compatibility (e.g., introducing asyncio in some component which sits on top of the synchronous function calls this interface exposes), but should generally be viewed as suboptimal--it is preferable in a situation like this to simply expose the underlying async interfaces.

Second, this class can be used to delegate asynchronous work from one thread to another, using its asynchronous interface.

Methods

await_coro_and_return_result

View source

Runs coroutine in the managed event loop, returning the result.

run_coro_and_return_result

View source

Runs coroutine in the managed event loop, returning the result.