API coroutine.create
(Redirected from API coroutine.wrap)
Jump to navigation
Jump to search
Creates a coroutine capable of yielding.
co = coroutine.create(workload) resumeFunc = coroutine.wrap(workload)
Arguments
- workload
- function - A function that may yield with coroutine.yield().
Returns
- co
- thread - A complete coroutine usable with the coroutine library.
- resumeFunc
- function - A single function to begin/resume the workload.
Details
- The workload is suspended until begun or resumed by coroutine.resume(co) or
resumeFunc()
.
Example
Yield part-way during a workload.
local function workload()
-- do something
coroutine.yield()
-- do something after resuming
end
local resumeFunc = coroutine.wrap(workload)
resumeFunc() -- top of the function
-- do something
resumeFunc() -- from yield() onward
External links
- Roberto lerusalimschy 2003, Programming in Lua, Chapter 9.1: Coroutine Basics.