From: Francis Cianfrocca Date: 2006-12-01T07:25:35+09:00 Subject: Re: Timers, scheduling and Ruby On 11/30/06, Damphyr wrote: > M. Edward (Ed) Borasky wrote: > > >> So, is there a library that will give me timers, a nice way to > >> configure them and a nice event driven interface? :) > >> Cheers, > >> V.- > > Event Machine? > I'm not sure about this. EventMachine seems geared towards networking. > I just want a class that will tick away on it's own thread and fire > events at designated time points. > My requirements include firing at intervals (every thirty minutes, every > two days), once (in thirty minutes, on 1/1/2007 at 0:00 etc.) and I > would like to have named events if possible. > Getting the events should be as simple as observing the timer. > So will anybody save me the work or do I have to code the beast? > Cheers, > V.- > > -- > http://www.braveworld.net/riva > > Try this in EventMachine: require 'rubygems' require 'eventmachine' EventMachine.run { EventMachine.add_periodic_timer(60) { # The code in this block gets executed every sixty seconds } EventMachine.add_periodic_timer(3600) { # The code in this block gets executed once an hour } } You can read the timer definitions out of a config file, configure them dynamically on the fly, or build them with a GUI.