kopia lustrzana https://github.com/micropython/micropython-lib
uasyncio: Implement run_until_complete().
rodzic
a64c7cbd57
commit
67b713535b
|
@ -77,6 +77,8 @@ class EventLoop:
|
||||||
self.remove_reader(arg.fileno())
|
self.remove_reader(arg.fileno())
|
||||||
elif isinstance(ret, IOWriteDone):
|
elif isinstance(ret, IOWriteDone):
|
||||||
self.remove_writer(arg.fileno())
|
self.remove_writer(arg.fileno())
|
||||||
|
elif isinstance(ret, StopLoop):
|
||||||
|
return arg
|
||||||
elif isinstance(ret, type_gen):
|
elif isinstance(ret, type_gen):
|
||||||
self.call_soon(ret)
|
self.call_soon(ret)
|
||||||
elif ret is None:
|
elif ret is None:
|
||||||
|
@ -90,16 +92,11 @@ class EventLoop:
|
||||||
self.call_later(delay, cb, *args)
|
self.call_later(delay, cb, *args)
|
||||||
|
|
||||||
def run_until_complete(self, coro):
|
def run_until_complete(self, coro):
|
||||||
val = None
|
def _run_and_stop():
|
||||||
while True:
|
yield from coro
|
||||||
try:
|
yield StopLoop(0)
|
||||||
ret = coro.send(val)
|
self.call_soon(_run_and_stop())
|
||||||
except StopIteration as e:
|
self.run_forever()
|
||||||
print(e)
|
|
||||||
break
|
|
||||||
print("ret:", ret)
|
|
||||||
if isinstance(ret, SysCall):
|
|
||||||
ret.handle()
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
@ -152,6 +149,9 @@ class SysCall:
|
||||||
class Sleep(SysCall):
|
class Sleep(SysCall):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class StopLoop(SysCall):
|
||||||
|
pass
|
||||||
|
|
||||||
class IORead(SysCall):
|
class IORead(SysCall):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue