[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Idea for an event loop library
- From: Jorge <xxopxe@...>
- Date: Fri, 11 May 2012 14:11:50 -0300
On vie, 2012-05-11 at 09:56 -0500, Tim Caswell wrote:
> Please don't misunderstand me.
That's unavoidable, sadly :)
> 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
Ok, i'm a bit lost. How does an implicit coroutine suspension look like?
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