|
On vie, 2012-05-11 at 09:56 -0500, Tim Caswell wrote:That's unavoidable, sadly :)
> Please don't misunderstand me.
Ok, i'm a bit lost. How does an implicit coroutine suspension look like?
> My only warning is in making the suspension of the coroutine implicit.
> You can use coroutines and still be explicit about the points where
> your code can be suspended. For example, in Luvit, I added a little
> sugar called "fiber" that looks like this:
> https://github.com/luvit/luvit/blob/master/examples/fs-coroutines.lua
My tasks can relinquish control trough a bunch of calls, easily
spottable (sched.wait, sched.signal, sched.run, and some wrappers around
those). For example I have this helper function ("run on a signal")
--------------------------------------
M.sigrun = function ( f, waitd )
local wrapper = function()
while true do
f(M.wait(waitd))
end
end
return M.run( wrapper )
end
---------------------------------------
If the provided f doesn't explicitly yield (with a sched.signal or
something) it will run atomically. Or you mean, that I should *enforce*
that when used as this, f will not yield?
Jorge