On 4/11/2014 7:53 AM, Eike Decker wrote:
When several tasks need to get spawned at once this isn't too difficult
to achieve as well:
---
local function script2()
   local coro = coroutine.running()
   local data1, data2
   local err1, err2
   fs.readFile("foo.lua", function(err, data)
     err1, data1 = err, data
     coroutine.resume(coro)
   end)
   fs.readFile("foo.lua", function(err, data)
     err2, data2 = err, data
     coroutine.resume(coro)
   end)
   coroutine.yield() -- first
   coroutine.yield() -- second
   p({err1=err1,err2=err2,data1=data1,data2=data2})
end

local coro = coroutine.create(script2)
coroutine.resume(coro);
---

Thats very cool.

Maybe make a yeild_n() wrapper for arbitrary-number scatter gather:

yeild_n(2)

Ross.

--
You received this message because you are subscribed to the Google Groups 
"luvit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to