coroutine
Using Coroutines
local function task(...)
-- This function might do some work for a bit then yield some value
coroutine.yield("first") -- To be returned by coroutine.resume()
-- The function continues once it is resumed again
return "second"
end
local taskCoro = coroutine.create(task)
-- Call resume for the first time, which runs the function from the beginning
local success, result = coroutine.resume(taskCoro, ...)
print(success, result) --> true, first (task called coroutine.yield())
-- Continue running the function until it yields or halts
success, result = coroutine.resume(taskCoro)
print(success, result) --> true, second (task halted because it returned "second")Status
Meaning
Wrapping Coroutines
Producer Pattern Example
Coroutine Functions
Last updated
Was this helpful?
