first save
This commit is contained in:
29
async.py
Normal file
29
async.py
Normal file
@@ -0,0 +1,29 @@
|
||||
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())
|
||||
Reference in New Issue
Block a user