Is there any timing class in the standard lib?

Hi guy,
I 'm doing a deamon that call a method every hour. Is there any class in
the standard library that I can use for counting the time?
Thai

I 'm doing a deamon that call a method every hour. Is there
any class in
the standard library that I can use for counting the time?

If it’s only going to do something every hour, are you sure you want a
daemon? Why not just have it run in a cron job (or scheduled task on
windows). If it’s a daemon, it’s going to sit there and consume memory
when it’s not doing anything.

If you really want your process to sit around, either use sleep(60*60)
or if you need more accuracy than that, do some calculations with
DateTime to figure out how long it will be till the next hour mark.

Daniel S. wrote:

If you really want your process to sit around, either use sleep(60*60)
or if you need more accuracy than that, do some calculations with
DateTime to figure out how long it will be till the next hour mark.

Thanks 4 your advice but this’s part of the requirements, I have no
access to system util. For testing, i try

class RSSdeamon
def start
puts “deamon started”
while true
sleep(5)
puts “deamon running”
end
end
end

myProc = RSSdeamon.new()
myProc.start

It doesnt print even a single line. Am I missing something in concurrent
programming?

myProc = RSSdeamon.new()
myProc.start

It doesnt print even a single line. Am I missing something in
concurrent
programming?

No, but I’m guessing you’re running windows and you’re missing something
in IO flushing. stdout doesn’t get flushed automatically by puts.

Try putting a STDOUT.flush after your puts.

Daniel S. wrote:

myProc = RSSdeamon.new()
myProc.start

It doesnt print even a single line. Am I missing something in
concurrent
programming?

No, but I’m guessing you’re running windows and you’re missing something
in IO flushing. stdout doesn’t get flushed automatically by puts.

Try putting a STDOUT.flush after your puts.
Thanks man, it’s working now. BTW, in the case of not using STDOUT, the
methd puts is actually executed but only the result is not printed out,
am i correct?

Daniel S. wrote:

Try putting a STDOUT.flush after your puts.

Some OSs, like linux, only flush the buffer to the target (STDOUT, in
this case) when the internal storage buffer is full or when a certain
event happens. Besides forcing flushing the buffer, One of this
events is, in many cases, the occurence of a “\n”. At least, that’s
my experience.

Paulo Jorge Duarte
[email protected]