Skip to content

Commit 67b7135

Browse files
committed
uasyncio: Implement run_until_complete().
1 parent a64c7cb commit 67b7135

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

uasyncio/uasyncio.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def run_forever(self):
7777
self.remove_reader(arg.fileno())
7878
elif isinstance(ret, IOWriteDone):
7979
self.remove_writer(arg.fileno())
80+
elif isinstance(ret, StopLoop):
81+
return arg
8082
elif isinstance(ret, type_gen):
8183
self.call_soon(ret)
8284
elif ret is None:
@@ -90,16 +92,11 @@ def run_forever(self):
9092
self.call_later(delay, cb, *args)
9193

9294
def run_until_complete(self, coro):
93-
val = None
94-
while True:
95-
try:
96-
ret = coro.send(val)
97-
except StopIteration as e:
98-
print(e)
99-
break
100-
print("ret:", ret)
101-
if isinstance(ret, SysCall):
102-
ret.handle()
95+
def _run_and_stop():
96+
yield from coro
97+
yield StopLoop(0)
98+
self.call_soon(_run_and_stop())
99+
self.run_forever()
103100

104101
def close(self):
105102
pass
@@ -152,6 +149,9 @@ def handle(self):
152149
class Sleep(SysCall):
153150
pass
154151

152+
class StopLoop(SysCall):
153+
pass
154+
155155
class IORead(SysCall):
156156
pass
157157

0 commit comments

Comments
 (0)