concurrency with asyncio running multiple tasks in many cases it is useful to be able to run several tasks concurrently there are two options provided for this the asyncio gather(and the asyncio as_completed(functionwe will look at both in this section collating results from multiple tasks it is often useful to collect all the results from set of tasks together and to continue only once all the results have been obtained when using threads or processes this can be achieved by starting multiple threads or processes and then using some other object such as barrier to wait for all the results to be available before continuing within the async io library all that is required is to use the asyncio gather(function with list of the async functions to runfor exampleimport asyncio import random async def worker()print('worker will take some time'await asyncio sleep( result random randint( , print('worker done it'return result async def do_something()print('do_something will wait for worker'run three calls to worker concurrently and collect results results await asyncio gather(worker()worker()worker()print('results from calls:'resultsdef main(print('main starting'asyncio run(do_something()print('main done'if __name__ ='__main__'main(in this program the do_something(function uses results await asyncio gather(worker()worker()worker()to run three invocations of the worker(function in three separate tasks and to wait for the results of all three to be made available before they are returned as list of values and stored in the results variable