From: ara.t.howard@... Date: 2007-02-24T00:42:39+09:00 Subject: Re: Cute little simple scheduling code hack On Fri, 23 Feb 2007, John Mettraux wrote: > Hi, > > I had come up with that : > > http://openwferu.rubyforge.org/scheduler.html looks very interesting! > advantage : one thread for all the tasks disadvantage : has to wake up to > pool its jobqueue hmmm. is that even possible? harp :~/openwferu/trunk/openwfe-ruby > cat a.rb require "time" require "openwfe/util/otime" require "openwfe/util/scheduler" include OpenWFE scheduler = Scheduler.new i = -1 scheduler.schedule('*/1 * * * *') do 4.times{ puts Time.now.iso8601(2); sleep 30 } ### this takes 120s! puts(i += 1) end scheduler.sstart STDIN.gets harp :~/openwferu/trunk/openwfe-ruby > RUBYLIB=lib ruby a.rb 2007-02-23T08:29:00.22-07:00 2007-02-23T08:29:30.22-07:00 2007-02-23T08:30:00.22-07:00 2007-02-23T08:30:30.22-07:00 0 2007-02-23T08:31:00.47-07:00 2007-02-23T08:31:30.47-07:00 2007-02-23T08:32:00.47-07:00 2007-02-23T08:32:30.47-07:00 1 2007-02-23T08:33:00.73-07:00 2007-02-23T08:33:30.73-07:00 2007-02-23T08:34:00.73-07:00 2007-02-23T08:34:30.73-07:00 2 2007-02-23T08:35:00.98-07:00 2007-02-23T08:35:30.98-07:00 2007-02-23T08:36:00.98-07:00 2007-02-23T08:36:30.98-07:00 3 2007-02-23T08:38:00.23-07:00 2007-02-23T08:38:30.23-07:00 ... ... ... it seems like a single threaded/processed scheduler is an imposibility? nevertheless i've already found a use for this code in a situation where i don't care if events are fired precisely (as is possible) as i declare them or not. cheers. -a -- be kind whenever possible... it is always possible. - the dalai lama