30 lines
542 B
Python
30 lines
542 B
Python
import uasyncio as asyncio # type: ignore
|
|
|
|
|
|
async def task1():
|
|
for i in range(5):
|
|
print('Task 1:', i)
|
|
await asyncio.sleep(1) # Non-blocking sleep
|
|
|
|
|
|
async def task2():
|
|
for i in range(5):
|
|
print('Task 2:', i)
|
|
await asyncio.sleep(2) # Different sleep time
|
|
|
|
|
|
async def task3():
|
|
for i in range(5):
|
|
print('Task 3:', i)
|
|
await asyncio.sleep(4) # Different sleep time
|
|
|
|
|
|
async def main():
|
|
# Run both tasks concurrently
|
|
await asyncio.gather(task1(), task2(), task3())
|
|
print("we're done.")
|
|
|
|
|
|
# Run the event loop
|
|
asyncio.run(main())
|