extmod/uasyncio: Implement Loop.stop() to stop the event loop.

This commit is contained in:
Damien George
2020-03-30 14:58:13 +11:00
parent 711dd392d3
commit b389bc0afa
4 changed files with 74 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
# Test Loop.stop() to stop the event loop
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task():
print("task")
async def main():
print("start")
# Stop the loop after next yield
loop.stop()
# Check that calling stop() again doesn't do/break anything
loop.stop()
# This await should stop
print("sleep")
await asyncio.sleep(0)
# Schedule stop, then create a new task, then yield
loop.stop()
asyncio.create_task(task())
await asyncio.sleep(0)
# Final stop
print("end")
loop.stop()
loop = asyncio.get_event_loop()
loop.create_task(main())
for i in range(3):
print("run", i)
loop.run_forever()

View File

@@ -0,0 +1,7 @@
run 0
start
sleep
run 1
run 2
task
end