diff options
author | Damien George <damien.p.george@gmail.com> | 2020-03-30 14:58:13 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-04-02 00:14:18 +1100 |
commit | b389bc0afaaa5a16dc11daaed056d89ea3da3b83 (patch) | |
tree | 832f5198746359a7c009dff8ba34068ecc9c5166 /extmod/uasyncio/core.py | |
parent | 711dd392d3800f9513c0a534cf8ecd9c3bfd27e0 (diff) | |
download | micropython-b389bc0afaaa5a16dc11daaed056d89ea3da3b83.tar.gz micropython-b389bc0afaaa5a16dc11daaed056d89ea3da3b83.zip |
extmod/uasyncio: Implement Loop.stop() to stop the event loop.
Diffstat (limited to 'extmod/uasyncio/core.py')
-rw-r--r-- | extmod/uasyncio/core.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/extmod/uasyncio/core.py b/extmod/uasyncio/core.py index 4a8597a3f2..dd0229ee45 100644 --- a/extmod/uasyncio/core.py +++ b/extmod/uasyncio/core.py @@ -214,17 +214,33 @@ def run(coro): # Event loop wrapper +async def _stopper(): + pass + + +_stop_task = None + + class Loop: def create_task(coro): return create_task(coro) def run_forever(): - run_until_complete() + global _stop_task + _stop_task = Task(_stopper(), globals()) + run_until_complete(_stop_task) # TODO should keep running until .stop() is called, even if there're no tasks left def run_until_complete(aw): return run_until_complete(_promote_to_task(aw)) + def stop(): + global _stop_task + if _stop_task is not None: + _task_queue.push_head(_stop_task) + # If stop() is called again, do nothing + _stop_task = None + def close(): pass |