File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 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
177177In essence, on every callback, we take 1 step forward in the coroutine.
178178
179179``` 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 )
181183 local step = nil
182184 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
189188 (callback or function () end )(ret )
189+ else
190+ assert (type (ret ) == " function" , " type error :: expected func" )
191+ ret (step )
190192 end
191193 end
192194 step ()
193195end
194-
195196```
196197
197198Notice that we also make pong call a callback once it is done.
You can’t perform that action at this time.
0 commit comments