summaryrefslogtreecommitdiff
path: root/extmod/uasyncio/event.py
diff options
context:
space:
mode:
authorNed Konz <ned@productcreationstudio.com>2021-09-01 10:48:15 -0700
committerDamien George <damien@micropython.org>2022-08-12 17:06:28 +1000
commit5543b2a9cc7381931431c69d93a77ba5d5d58e2e (patch)
treeb1c517f319d16e5a893cfa08fcde4e7a105dc15b /extmod/uasyncio/event.py
parentcf90e24335652462bb7eb4bd105e061683bc316a (diff)
extmod/uasyncio: Add clear method to ThreadSafeFlag.
This is useful in situations where the ThreadSafeFlag is reused and needs to be cleared of any previous, unwanted event. For example, clear the flag at the start of an operation, trigger the operation (eg an I2C write), then (a)wait for an external event to set the flag (eg a pin IRQ). Further events may trigger the flag again but these are unwanted and should be cleared before the next cycle starts.
Diffstat (limited to 'extmod/uasyncio/event.py')
-rw-r--r--extmod/uasyncio/event.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/extmod/uasyncio/event.py b/extmod/uasyncio/event.py
index c48904b98..654ccefa9 100644
--- a/extmod/uasyncio/event.py
+++ b/extmod/uasyncio/event.py
@@ -36,7 +36,7 @@ class Event:
# MicroPython-extension: This can be set from outside the asyncio event loop,
# such as other threads, IRQs or scheduler context. Implementation is a stream
# that asyncio will poll until a flag is set.
-# Note: Unlike Event, this is self-clearing.
+# Note: Unlike Event, this is self-clearing after a wait().
try:
import uio
@@ -52,6 +52,9 @@ try:
def set(self):
self._flag = 1
+ def clear(self):
+ self._flag = 0
+
async def wait(self):
if not self._flag:
yield core._io_queue.queue_read(self)