76f03a2bee
This allows a small wrapper class to be written ```py class AsyncEventQueue: def __init__(self, events): self._events = events async def __await__(self): yield asyncio.core._io_queue.queue_read(self._events) return self._events.get() def __enter__(self): return self def __exit__(self, exc_type, exc_value, traceback): pass ``` and used to just "await" the next event: ```py async def key_task(): print("waiting for keypresses") with keypad.KeyMatrix([board.D4], [board.D5]) as keys, AsyncEventQueue(keys.events) as ev: while True: print(await ev) ``` Because checking the empty status of the EventQueue does not enter CircuitPython bytecode, it's assumed (but not measured) that this is more efficient than an equivalent loop with an `await async.sleep(0)` yield and introduces less latency than any non-zero sleep value. |
||
---|---|---|
.. | ||
__init__.c | ||
__init__.h | ||
Event.c | ||
Event.h | ||
EventQueue.c | ||
EventQueue.h | ||
KeyMatrix.c | ||
KeyMatrix.h | ||
Keys.c | ||
Keys.h | ||
ShiftRegisterKeys.c | ||
ShiftRegisterKeys.h |