I am trying to learn native coroutine. I run the above example and I don't understand it.
Here is the example.
import asyncio
async def say_after(delay, what):
await asyncio.sleep(delay)
print(what)
async def main():
task1 = asyncio.create_task(
say_after(3, "A")
)
task2 = asyncio.create_task(
say_after(2, "B")
)
print("----0")
await task1
print("----1")
await task2
asyncio.run(main())
I heard that await waits for the task to finish.
I expected to be printed in the order
A
B
----1
However, in the example above, ----1 is output after both B and A are printed.
The following is the output printed.
----0
B
A
----1
Why is this output created?
Do you know a site that has a collection of useful examples for studying native coroutine?