lua-users home
lua-l archive

Re: Idea for an event loop library

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


Another possible source of inspiration:
http://lua-av.mat.ucsb.edu/blog/?p=137
function clockprinter(name, period) 
 while true do
 print(now(), name) 
 wait(period)
 end
end
go(clockprinter, "T O C K!", 4) 
go(clockprinter, "...tick...", 1)
We aimed for a concise syntax and generalizable capability. The default scheduler is driven from a timer, but other schedulers can be created and driven arbitrarily. Coroutines can be scheduled against timeouts or string-identifed events. 
It should be easy to implement this on top of an arbitrary event loop. 
I can turn this into a stand-alone module if there is interest.
On May 10, 2012, at 4:45 AM, Valerio Schiavoni wrote:
> Hello Rob,
> 
> take a look at what we have inside the Splay runtime, as it sounds very close to that:
> 
> http://www.splay-project.org/manual#events
> 
> best,
> valerio
> 
> On Wed, May 9, 2012 at 1:22 PM, Rob Hoelz <rob@hoelz.ro> wrote:
> Hello list,
> 
> I've been meaning to write a new event library for a while, but I
> thought I'd throw the idea at the list first to see if it has merit.
> 
> Basically, I want to create an event library for Lua that sits on top
> of another event library (luaevent for now, but I would probably make
> the system flexible enough for a different library should that be
> desired). It would provide a simpler interface for events, so you could
> do something like this:
> 
> local w = ev:timer {
> interval = 1,
> callback = function()
> print 'One second has passed!'
> end
> }
> 
> However, that part is just the gravy. The point of doing a whole new
> library would be to make the entire thing coroutine-based. Think of it
> like Copas, but applied to generic events instead of just TCP/IP
> sockets. So let's say I wanted to print 'hello' a second after a user
> clicked a button in a GUI. I could do something like this:
> 
> -- this assumes that the GUI plays nicely with the event loop
> button:onclick(function()
> ev:sleep(1)
> print 'hi'
> end)
> 
> and other events would continue to fire while the button handler is
> sleeping. Also, you could write a timer-based event like this:
> 
> ev:go(function()
> while true do
> ev:sleep(1)
> print 'waking up!'
> end
> end)
> 
> The library would also provide other operations for waiting for an event
> to happen.
> 
> So, what do you all think? Does this idea sound cool to you too, or
> does it sound useless/dumb/too magical/etc?
> 
> -Rob
> 
> 

AltStyle によって変換されたページ (->オリジナル) /