SlyAPI.asyncy#

Useful classes and functions for asynchronous programming.

Functions

unmanage_async_context(context)

Extract an async context manager's value without manually managing its lifetime.

Classes

AsyncLazy(gen)

Async iterator which does not accumulate any results unless awaited.

AsyncTrans

alias of AsyncLazy

SlyAPI.asyncy.unmanage_async_context(context)[source]#

Extract an async context manager’s value without manually managing its lifetime. The context manager is entered until set() is called on the returned event.

thats it unmanages your async context manager

Parameters:

context (AbstractAsyncContextManager[T]) –

Return type:

tuple[_asyncio.Task[~T], asyncio.locks.Event]

class SlyAPI.asyncy.AsyncLazy(gen)[source]#

Bases: Generic[T]

Async iterator which does not accumulate any results unless awaited. Awaiting instances will return a list of the results.

Parameters:

gen (AsyncGenerator[T, None]) –

gen: AsyncGenerator[T, None]#
__await__()[source]#

Yield the aggregate results of the generator as a list.

Return type:

Generator[Any, None, list[~T]]

map(f)[source]#

Apply a function to each item that is yielded.

Parameters:

f (Callable[[T], U]) –

Return type:

AsyncLazy[U]

classmethod wrap(fn)[source]#

Convert an async generator async function to return an AsyncLazy instance.

Parameters:

fn (Callable[[~T_Params], AsyncGenerator[T, None]]) –

SlyAPI.asyncy.AsyncTrans#

alias of AsyncLazy