feat: Semaine 9
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import asyncio
|
||||
|
||||
async def coro(numbers):
|
||||
await asyncio.sleep(min(numbers))
|
||||
return list(reversed(numbers))
|
||||
|
||||
async def main():
|
||||
task1 = asyncio.create_task(coro= coro([10, 5, 2]))
|
||||
task2 = asyncio.create_task(coro= coro([3, 2, 1]))
|
||||
for task in asyncio.as_completed([task1, task2]):
|
||||
result = await task
|
||||
print(f"{type(task)=}")
|
||||
print(result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
||||
"""
|
||||
await coro(utine) : exécute immédiatement et attend qu'elle finisse
|
||||
|
||||
create_task() : planifie une coroutine en arrière-plan
|
||||
"""
|
||||
Reference in New Issue
Block a user