-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Description
A common situation when interfacing hardware is the case where a device which is normally not ready needs to be polled. One solution is along the lines of
async def poll(device):
while True:
if device.ready():
device.handle_data()
yield
This works but has a high worst case latency. If there are N coroutines each with a maximum latency of T between yield
statements, an interval of up to NT will exist between calls to device.ready(). This can be reduced to T if there is a way to delegate the polling to the scheduler. In other words to provide a facility to schedule on an event (cf the Poller
class in my scheduler).
Any comments on ways to achieve this with uasyncio? Perhaps there's a solution which I've missed.
To anyone interested I've ported my classes for debounced switches and pushbuttons to asyncio and plan to extend this to other drivers. Preliminary code and docs here.