lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I haven't tried your code, but this is a pleasant
way to restructure many types of programs - since a
couple of weeks ago I use a very similarly-implemented
asynchronous call mechanism in Lua and it's really handy.

Since there's a coroutine scheduler, it's also a nice
way to sneakily avoid Lua's restriction on yielding
from i.e. C-called callbacks, since the coroutine
can poll a closure shared with the callback waiting
for the callback to set it to some interesting result.

I use this to turn callbacky stuff like DNS lookups
and timers, and a variety of poll-y stuff, into a set
of utility functions that simply block the calling
function, allowing others to continue, instead of
having to turn the flow into a bunch of nested

Your implementation looks quite straightforward and
compact - mine has a bit more cruft that I needed
for supporting re-invokable scheduled functions and
sugaring the C-originating fake-yields and other stuff.