Coroutines offer a way to run different parts of a program in a somewhat concurrent
way, similar to threads. A function can be called as a coroutine, suspended with
yield() any number of times, and then resumed again at the same point.
function hey()
print("doing something")
yield()
print("doing the next thing")
yield()
print("finished")
end
c = cocreate(hey)
for i=1,3 do coresume(c) end
cocreate f
Create a coroutine for function f.
coresume c [p0 p1 ..]
Run or continue the coroutine c. Parameters p0, p1.. are passed to the
coroutine's function.
Returns true if the coroutine completes without any errors
Returns false, error_message if there is an error.
** Runtime errors that occur inside coroutines do not cause the program
to stop running. It is a good idea to wrap coresume() inside an assert().
If the assert fails, it will print the error message generated by
coresume.
assert(coresume(c))
costatus c
Return the status of coroutine c as a string:
"running"
"suspended"
"dead"
yield
Suspend execution and return to the caller.