From: John Mettraux Date: 2007-02-23T16:10:05+09:00 Subject: Re: Cute little simple scheduling code hack 2007/2/23, KCons : > I'm sure there is some far superior prior art out there somewhere, but > this is a useful little hack I threw together today that I thought > someone else might find interesting. > > I wanted to do a little task every few seconds for some duration of > time, and after a bit of overkill I came up with a little library that > lets me do stuff like: > > every( 5.seconds ).for( 2.days ) { puts "Chunky bacon, k?" } > > or > > every( 2.minutes ).until ( Time.now + 4.hours ) { dance_for_a_while } > > or even > > class String > def gradual_out( n = 1 ) > ix = 0 > every( n.seconds ).unless(lambda {ix >= size}) do > print self[ix].chr > ix += 1 > end > end > end > > "Tuesday is the new Thursday".gradual_out( 400.milliseconds ) Hi, I had come up with that : http://openwferu.rubyforge.org/scheduler.html advantage : one thread for all the tasks disadvantage : has to wake up to pool its jobqueue But your approach is definitely more cute and more 'rubystic'. Quick question : is the "rescue Interrupt" really needed ? Does it avoid some "under the carpet thread problems" ? Best regards, -- John Mettraux -///- http://jmettraux.openwfe.org