From: Jason Vinson Date: 2006-09-10T04:20:56+09:00 Subject: Re: Timer Task? -----Original Message----- From: Paul Lutus [mailto:nospam@nosite.zzz] Sent: Saturday, September 09, 2006 1:20 PM To: ruby-talk ML Subject: Re: Timer Task? Jason Vinson wrote: /... > I guess my real question is the preferred approach > something like this? > > notifier = SnarlMail.new("imap.mailserver.com", "username", "passwd") > > while(true) do > notifier.check > sleep 60 > end > > Does sleep cost anything in terms of resources, and if so what is > "cheaper"? AFAIK "sleep" is a perfectly adequate way to idle a thread, and it has the advantage of being trivial to implement. I have recently seen Ruby threads that used "sleep" be idled by the thread manager, never to be called again, but this has to do with Ruby threads within a Ruby process, not native threads represented by particular Ruby applications. [Somewhat OT] Have you considered using OS-specific facilities like "cron" instead of "sleep" for scheduling? I use cron for most of these periodic, relatively low-powered tasks because it is easy to add a task to cron's list of jobs, and it burdens the system less than maintaining a bunch of sleeping processes -- cron loads, runs, and unloads its tasks, while a sleeping process represents an ongoing use of resources. -- Paul Lutus http://www.arachnoid.com ...................................... Thanks for the reply Paul, The main reason for maintaining a Thread is because there's a tiny bit of state involved (I only want to report new mail, not the same new mail over and over again). I'm open to other alternatives, but writing out to the file system seems like the only other option, which I'd prefer not to do. Jason