If I have some remote resource which continuously produces one or more items and writes them somewhere, what is the best way to deliver the data to the user?
def parse_rawdata(rawdata): return rawdata.split(b'SPLITTOKEN') async def res(): rawdata = await connection.read() data_list = parse_rawdata(rawdata) return data_list
What is the best interface for an user to consume the resources? One would be to simply return the whole data list in a loop:
class MyObj: def __aiter__(self): return self async def __anext__(self): return await res()
So the user is expected to do an async loop followed by a normal loop to iterate over the data (not very nice). Another would be async generators, so instead I would do:
async def res(): rawdata = await connection.read() data_list = parse_rawdata(rawdata) for ele in data_list: yield ele
Unfortunately this is also not very nice, because as of the latest version of curio, the async for loop needs to be wrapped in curio.finalize…