From: Paul Lutus Date: 2006-09-10T02:20:16+09:00 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