forked from peterhinch/micropython-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.py
39 lines (32 loc) · 965 Bytes
/
io.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# io.py Failed attempt to use uasyncio IORead mechanism in a custom class.
# It turns out that the necessary support has not been implemented, and
# it is unlikely that this will occur.
import uasyncio as asyncio
MP_STREAM_POLL_RD = 1
MP_STREAM_POLL = 3
import uasyncio as asyncio
class Device():
def __init__(self):
self.ready = False
def fileno(self):
return 999
def ioctl(self, cmd, flags):
res = 0
print('Got here')
if cmd == MP_STREAM_POLL and (flags & MP_STREAM_POLL_RD):
if self.ready:
res = MP_STREAM_POLL_RD
return res
def read(self):
return
def write(self):
return
async def readloop(self):
while True:
print('About to yield')
yield asyncio.IORead(self)
print('Should never happen')
loop = asyncio.get_event_loop()
device = Device()
loop.create_task(device.readloop())
loop.run_forever()