Currently, the generator examples and gen_to_unit are not asynchronous. This is probably for the best as it's much more straightforward to implement and test the generator when we don't need to setup the async context. However, if there is a method/Unit that would truly benefit from asyncio (e.g., this list, something that needs to sleep, or if I expose async methods in pycbsdk) then the current generator examples and gen_to_unit are incompatible.
There are asynchronous generators in Python. As far as I can tell, the only difference is the method should be async def'd and you interact with it via asend or anext instead of send and next. Edit: Silly me, our Unit's subscriber and publisher methods are async generators.
How can we support asynchronous generators, while keeping synchronous generators as the default?
[ ] Example implementation with manual result = await gen.asend(msg) inside a Unit.
[ ] Either agen_to_unit or augment current gen_to_unit to recognize async def generators (inspect.iscoroutinefunction(generator)).
[ ] Either aconsumer or augment @consumer decorator to recognize async def.
Currently, the generator examples and
gen_to_unit
are not asynchronous. This is probably for the best as it's much more straightforward to implement and test the generator when we don't need to setup the async context. However, if there is a method/Unit that would truly benefit fromasyncio
(e.g., this list, something that needs to sleep, or if I expose async methods inpycbsdk
) then the current generator examples andgen_to_unit
are incompatible.There are asynchronous generators in Python. As far as I can tell, the only difference is the method should be
async def
'd and you interact with it viaasend
oranext
instead ofsend
andnext
. Edit: Silly me, our Unit's subscriber and publisher methods are async generators.How can we support asynchronous generators, while keeping synchronous generators as the default?
result = await gen.asend(msg)
inside a Unit.agen_to_unit
or augment currentgen_to_unit
to recognize async def generators (inspect.iscoroutinefunction(generator)
).aconsumer
or augment@consumer
decorator to recognize async def.