lua.wetgenes.tasks.add_task
local thread=tasks:add_task({
id="test",
code=function(linda,task_id,task_idx,task)
while true do
local _,memo= linda:receive( 0 , task_id )
if memo then
...
end
end
end,
})
Create a task with various preset values similar to a thread except inside a coroutine on the calling thread. As this function is inside a coroutine you must yield regulary this yield will then continue on the next update. Probably called once ever 60th of a second.
id
A unique id string to be used by lindas when sending messages into this task. The function is expected to sit in an infinite loop testing this linda socket and then yielding if there is nothing to do.
count
The number of tasks to create, they will all use the same instanced code function so should be interchangable and it should not matter which task we are actually running code on. If you expect the task to maintain some state between memos, then this must be 1 .
code
A lua function to run inside a coroutine, this function will recieve tasks.linda (which is a colinda) and the task.id for comunication and an index so we know which of the count tasks we are (mostly for debugging) and finally the task table itself which make sense to share with coroutines.