kopia lustrzana https://github.com/micropython/micropython-lib
asyncio: Support read/write syscalls, and route vals both ways between coros.
rodzic
85071250f1
commit
ac0038f9a7
|
@ -55,12 +55,22 @@ class EventLoop:
|
||||||
else:
|
else:
|
||||||
delay = 0
|
delay = 0
|
||||||
try:
|
try:
|
||||||
ret = next(cb)
|
if args == ():
|
||||||
# print("ret:", ret)
|
args = (None,)
|
||||||
|
print("Send args:", args)
|
||||||
|
ret = cb.send(*args)
|
||||||
|
print("ret:", ret)
|
||||||
|
if isinstance(ret, SysCall):
|
||||||
if isinstance(ret, Sleep):
|
if isinstance(ret, Sleep):
|
||||||
delay = ret.args[0]
|
delay = ret.args[0]
|
||||||
|
elif isinstance(ret, IORead):
|
||||||
|
self.add_reader(ret.obj.fileno(), lambda f: self.call_soon(cb, f), ret.obj)
|
||||||
|
continue
|
||||||
|
elif isinstance(ret, IOWrite):
|
||||||
|
self.add_writer(ret.obj.fileno(), lambda f: self.call_soon(cb, f), ret.obj)
|
||||||
|
continue
|
||||||
except StopIteration as e:
|
except StopIteration as e:
|
||||||
print(c, "finished")
|
print(cb, "finished")
|
||||||
continue
|
continue
|
||||||
#self.q.append(c)
|
#self.q.append(c)
|
||||||
self.call_later(delay, cb, *args)
|
self.call_later(delay, cb, *args)
|
||||||
|
@ -116,6 +126,16 @@ class Sleep(SysCall):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
time.sleep(self.args[0])
|
time.sleep(self.args[0])
|
||||||
|
|
||||||
|
class IORead(SysCall):
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
self.obj = obj
|
||||||
|
|
||||||
|
class IOWrite(SysCall):
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
self.obj = obj
|
||||||
|
|
||||||
|
|
||||||
def get_event_loop():
|
def get_event_loop():
|
||||||
return EpollEventLoop()
|
return EpollEventLoop()
|
||||||
|
|
Ładowanie…
Reference in New Issue