File tree 1 file changed +10
-10
lines changed 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ def run_forever(self):
77
77
self .remove_reader (arg .fileno ())
78
78
elif isinstance (ret , IOWriteDone ):
79
79
self .remove_writer (arg .fileno ())
80
+ elif isinstance (ret , StopLoop ):
81
+ return arg
80
82
elif isinstance (ret , type_gen ):
81
83
self .call_soon (ret )
82
84
elif ret is None :
@@ -90,16 +92,11 @@ def run_forever(self):
90
92
self .call_later (delay , cb , * args )
91
93
92
94
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 ()
103
100
104
101
def close (self ):
105
102
pass
@@ -152,6 +149,9 @@ def handle(self):
152
149
class Sleep (SysCall ):
153
150
pass
154
151
152
+ class StopLoop (SysCall ):
153
+ pass
154
+
155
155
class IORead (SysCall ):
156
156
pass
157
157
You can’t perform that action at this time.
0 commit comments