API coroutine.create

From Warcraft Wiki
(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