diff options
author | Damien George <damien@micropython.org> | 2022-03-29 12:27:56 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-03-30 16:07:44 +1100 |
commit | 335002a4c020850591122d763324599e5edbe045 (patch) | |
tree | dba8360d7ab035b5dfe3044062e617fffd8d7966 /extmod/uasyncio/task.py | |
parent | a41bc5a7cadb5bea9b7800286b2f4ea4f9b26e1a (diff) | |
download | micropython-335002a4c020850591122d763324599e5edbe045.tar.gz micropython-335002a4c020850591122d763324599e5edbe045.zip |
extmod/uasyncio: Allow task state to be a callable.
This implements a form of CPython's "add_done_callback()", but at this
stage it is a hidden feature and only intended to be used internally.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/uasyncio/task.py')
-rw-r--r-- | extmod/uasyncio/task.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/extmod/uasyncio/task.py b/extmod/uasyncio/task.py index 26df7b1725..d775164909 100644 --- a/extmod/uasyncio/task.py +++ b/extmod/uasyncio/task.py @@ -123,7 +123,7 @@ class Task: def __init__(self, coro, globals=None): self.coro = coro # Coroutine of this Task self.data = None # General data for queue it is waiting on - self.state = True # None, False, True or a TaskQueue instance + self.state = True # None, False, True, a callable, or a TaskQueue instance self.ph_key = 0 # Pairing heap self.ph_child = None # Paring heap self.ph_child_last = None # Paring heap @@ -137,6 +137,9 @@ class Task: elif self.state is True: # Allocated head of linked list of Tasks waiting on completion of this task. self.state = TaskQueue() + elif type(self.state) is not TaskQueue: + # Task has state used for another purpose, so can't also wait on it. + raise RuntimeError("can't wait") return self def __next__(self): |