10000 asyncio: Support read/write syscalls, and route vals both ways betwee… · micropython/micropython-lib@ca9ea0d · GitHub
[go: up one dir, main page]

Skip to content

Commit ca9ea0d

Browse files
author
Paul Sokolovsky
committed
asyncio: Support read/write syscalls, and route vals both ways between coros.
1 parent 65f0a05 commit ca9ea0d

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

asyncio/asyncio.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,22 @@ def run_forever(self):
5555
else:
5656
delay = 0
5757
try:
58-
ret = next(cb)
59-
# print("ret:", ret)
60-
if isinstance(ret, Sleep):
61-
delay = ret.args[0]
58+
if args == ():
59+
args = (None,)
60+
print("Send args:", args)
61+
ret = cb.send(*args)
62+
print("ret:", ret)
63+
if isinstance(ret, SysCall):
64+
if isinstance(ret, Sleep):
65+
delay = ret.args[0]
66+
elif isinstance(ret, IORead):
67+
self.add_reader(ret.obj.fileno(), lambda f: self.call_soon(cb, f), ret.obj)
68+
continue
69+
elif isinstance(ret, IOWrite):
70+
self.add_writer(ret.obj.fileno(), lambda f: self.call_soon(cb, f), ret.obj)
71+
continue
6272
except StopIteration as e:
63-
print(c, "finished")
73+
print(cb, "finished")
6474
continue
6575
#self.q.append(c)
6676
self.call_later(delay, cb, *args)
@@ -116,6 +126,16 @@ class Sleep(SysCall):
116126
def handle(self):
117127
time.sleep(self.args[0])
118128

129+
class IORead(SysCall):
130+
131+
def __init__(self, obj):
132+
self.obj = obj
133+
134+
class IOWrite(SysCall):
135+
136+
def __init__(self, obj):
137+
self.obj = obj
138+
119139

120140
def get_event_loop():
121141
return EpollEventLoop()

0 commit comments

Comments
 (0)
0