I have read Peter's tutorial on Uasyncio V3, but am still a bit confused about the behaviors of `create_task()` and `await` and need some more education...
Regarding my confusion, I have a few sample codes as below.
Code: Select all
async def f1():
for _ in range(10):
print('f1')
await uasyncio.sleep_ms(500)
async def f2():
for _ in range(10):
print('f2')
await uasyncio.sleep_ms(1000)
async def m1():
uasyncio.create_task(f1())
await f2()
async def m2():
t = uasyncio.create_task(f1())
await t
async def m3():
await f1()
async def m4():
await f1()
await f2()
2. I seemed to get same results from running `m2()` and `m3()`, what's the difference between the two?
3. For `m4()`, `f2()` was executed only after the completion of `f1()`, although there's `await uasyncio.sleep_ms(500)` inside `f1()`, the program performed as if it's synchronous. Is it because there's no task running in the background so the program just got executed line by line? Pls correct me if I'm misunderstood.
Thanks,
Kaiyuan