File tree 1 file changed +25
-5
lines changed
1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -55,12 +55,22 @@ def run_forever(self):
55
55
else :
56
56
delay = 0
57
57
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
62
72
except StopIteration as e :
63
- print (c , "finished" )
73
+ print (cb , "finished" )
64
74
continue
65
75
#self.q.append(c)
66
76
self .call_later (delay , cb , * args )
@@ -116,6 +126,16 @@ class Sleep(SysCall):
116
126
def handle (self ):
117
127
time .sleep (self .args [0 ])
118
128
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
+
119
139
120
140
def get_event_loop ():
121
141
return EpollEventLoop ()
You can’t perform that action at this time.
0 commit comments