Suppose I have a Python iterator like this:
def my_iterator():
data = heavy_computation()
while data:
yield data
data = heavy_computation()
def client():
it = my_iterator()
for data in it:
result = post_processing(data)
print_to_file(result)
I want the iterator to start working on the next piece of data before the client asks for it. Is it possible to implement this type of behaviour using the python asyncio library, or any other more convenient method?
I'm new to the asyncio library, but it seems like the preferred way of handling concurrency in python. I'm open to other solutions as well.