Книга: Learning Concurrency in Python
Назад: Task functions
Дальше: The ensure_future(coro_or_future, *, loop=None) function

The as_completed(fs, *, loop=None, timeout=None) function

The as_completed function allows us to work with the results returned from all of our executed tasks as and when they are returned. These results could then be fed into a series of other coroutines for further processing or just simply logged somewhere depending on what your needs are.

We can use the as_completed() function as follows and iterate over the completed futures as and when they are returned:

for f in as_completed(fs):
result = yield from f
# Use result
Назад: Task functions
Дальше: The ensure_future(coro_or_future, *, loop=None) function