running multiple tasks this makes is very easy to work with multiple concurrent tasks and to collate their results note that in this code example the worker async function returns random number between and the output from this program ismain starting do_something will wait for worker worker will take some time worker will take some time worker will take some time worker done it worker done it worker done it results from calls[ main done as you can see from this all three of the worker invocations are started but then release the processor while they sleep after this the three tasks wake up and complete before the results are collected together and printed out handling task results as they are made available another option when running multiple tasks is to handle the results as they become availablerather than wait for all the results to be provided before continuing this option is supported by the asyncio as_completed(function this function returns an iterator of async functions which will be served up as soon as they have completed their work the for-loop construct can be used with the iterator returned by the functionhowever within the for loop the code must call await on the async functions returned so that the result of the task can be obtained for exampleasync def do_something()print('do_something will wait for worker'run three calls to worker concurrently and collect results for async_func in asyncio as_completed((worker(' ')worker(' ')worker(' ')))result await async_func print('do_something result:'resultnote that the asyncio as_completed(function takes container such as tuple of async functions