ezmsg-org / ezmsg

Pure-Python DAG-based high-performance SHM-backed pub-sub and multi-processing pattern
https://ezmsg.readthedocs.io/en/latest/
MIT License
9 stars 4 forks source link

[For Discussion] Should generator pattern use asynchronous generators? #84

Open cboulay opened 5 months ago

cboulay commented 5 months ago

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?