File tree 1 file changed +9
-8
lines changed
1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -177,21 +177,22 @@ The sole job of the `step` funciton is to take the place of the callback to all
177
177
In essence, on every callback, we take 1 step forward in the coroutine.
178
178
179
179
``` lua
180
- local pong = function (thread , callback )
180
+ local pong = function (func , callback )
181
+ assert (type (func ) == " function" , " type error :: expected func" )
182
+ local thread = co .create (func )
181
183
local step = nil
182
184
step = function (...)
183
- local go , ret = co .resume (thread , ... )
184
- if not go then
185
- assert (co .status (thread ) == " suspended" , ret )
186
- elseif type (ret ) == " function" then
187
- ret (step )
188
- else
185
+ local stat , ret = co .resume (thread , ... )
186
+ assert (stat , ret )
187
+ if co .status (thread ) == " dead" then
189
188
(callback or function () end )(ret )
189
+ else
190
+ assert (type (ret ) == " function" , " type error :: expected func" )
191
+ ret (step )
190
192
end
191
193
end
192
194
step ()
193
195
end
194
-
195
196
```
196
197
197
198
Notice that we also make pong call a callback once it is done.
You can’t perform that action at this time.
0 commit comments