Timers, scheduling and Ruby

here's what i'd like

   inclusive_endpoint = Time.now + 7.days

                                                      ^^^^^^^^
is there already a library/utility for the above somewhere?

   runt.next_times inclusive_endpoint #=> array of all times
covered between
                                       # now and endpoint,
'now' should be an
                                       # optional parameter
so multiple calls
                                       # can be made
transactional, eg
                                       #
                                       # runt.next_times
inclusive_endpoint, 'now' => Time.now
                                       # runt.next_times
inclusive_endpoint, :now => Time.now
                                       #

that way it's easy to do

   loop{
     now = Time.now

     inclusive_endpoint = now + sleep_interval

     runts.each do |runt|
       times = runt.next_times inclusive_endpoint, :now => now
       schedule_all_events times
     end

     sleep_until inclusive_endpoint
   }

make sense?

think so; will try to add this weekend. If I have questions may I
contact you offline? (I'm subscribed to CLR w/my work address -- cc'd
address above is perfect!)

thanks for a great lib btw!

np, thanks for the kind words! ...anyway, Martin Fowler did all the hard
work by coming up with the pattern in the first place...

Have a nice weekend all!

Matt

__mlipper__at__gmail_dot_com__

   inclusive_endpoint = Time.now + 6.days

                                                     ^^^^^^^^
is there already a library/utility for the above somewhere?

written many times, but here's mine:

   class Numeric
     def microseconds() Float(self * (10 ** -6)) end
     def milliseconds() Float(self * (10 ** -3)) end
     def seconds() self end
     def minutes() 60 * seconds end
     def hours() 60 * minutes end
     def days() 24 * hours end
     def weeks() 7 * days end
     def months() 30 * days end
     def years() 365 * days end
     def decades() 10 * years end

     %w[
       microseconds milliseconds seconds minutes hours days weeks months years decades
     ].each{|m| alias_method m.chop, m}
   end

you don't have to write that part :wink:

make sense?

think so; will try to add this weekend. If I have questions may I contact
you offline? (I'm subscribed to CLR w/my work address -- cc'd address above
is perfect!)

absolutely.

np, thanks for the kind words! ...anyway, Martin Fowler did all the hard

i dunno about that - having transcribed quite a few books/articles into code
myself - it's hard wrapping your head around someone else's ideas/code.

cheers.

-a

···

On Sat, 2 Dec 2006, Lipper, Matthew wrote:
--
if you want others to be happy, practice compassion.
if you want to be happy, practice compassion. -- the dalai lama