Provide an asynchronus equivalent to itertools.chain, and possibly more of itertools

I recently started to dive into asynchronous programming in Python. My program iterates over text from posts on a website and analyses it. I wanted to add the ability to asynchronously apply the same analysis to posts from multiple websites. It seemed likely to me that this would be something people commonly want to do, but I was surprised to find no built-in solution. There are a few relevant stack overflow posts: https://stackoverflow.com/questions/55299564/join-multiple-async-generators-... In which people suggest either using the library aiostream: https://aiostream.readthedocs.io/en/latest/operators.html#aiostream.stream.m... Or use an implementation based on `asyncio.Queue`. It seems to me that the aiostream solution goes beyond what I imagine most people would want to do. The solution using `asyncio.Queue` I think is fine, but is tricky to understand and a bit ugly to have to implement as a helper in every project looking to do this sort of thing. I propose there should be an asynchronous version of `itertools.chain` e.g. called `achain` which would allow users to write something like: ``` async for item in achain(async_gen1(), async_gen2(), async_gen3()): process(item) ``` I think it's very clear what this expression is doing and I can't imagine it's just me who'd find it useful. I have made an effort to implement at prototype version here: https://github.com/0Hughman0/achain/tree/no_context It works for the most basic case, but I imagine there's lots of nitty gritty regarding error handling etc. that I won't have done right. I'd love to hear others thoughts. Particularly whether you think this would be good to add to the standard library. It seems natural to me to try and make asynchronous compatible version of lots of the Python generators, e.g. `enumerate` and others from `itertools`. Many thanks, Hugh
participants (1)
-
rammers2@hotmail.co.uk