Skip to content

Commit d3adca2

Browse files
ms-jpqs1n7ax
authored andcommitted
new pong
1 parent b5f8191 commit d3adca2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,22 @@ The sole job of the `step` funciton is to take the place of the callback to all
177177
In 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()
193195
end
194-
195196
```
196197

197198
Notice that we also make pong call a callback once it is done.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy