So here's what I'm doing -- I have a ruby script that prints out information every minute. I've also set up a proc for a trap so that when the user hits ctrl-c, the process aborts. The code looks something like this:
switch = true
Signal.trap("SIGINT") do
switch = false
end
lastTime = Time.now
while switch do
if Time.now.min > lastTime.min then
puts "A minute has gone by!"
end
end
Now the code itself is valid and runs well, but it does a lot of useless work checking the value of switch
as often as it can. It uses up as much of the processor as it can get (at least, 100% of one core), so it's pretty wasteful. How can I do something similar to this, where an event is updated every so often, without wasting tons of cycles?
All help is appreciated and thanks in advance!