import asyncio
async def task(name, duration):
print(f"Task {name} started.")
await asyncio.sleep(duration)
print(f"Task {name} finished after {duration} seconds.")
async def main():
await asyncio.gather(
task("A", 2),
task("B", 1),
task("C", 3),
)
asyncio.run(main())
# Output: Tasks A, B, and C execute concurrently.
Coroutines can mimic generator pipelines, but they work asynchronously: