i need a timer for the program i am writing but i don’t know the code so
please someone help me to write timer…
thanx for your help…
i need a timer for the program i am writing but i don’t know the code so
please someone help me to write timer…
thanx for your help…
a) timeout:
require ‘timeout’
timeout(4) do
code in here will only run for 4 seconds
end
If you look at the implementation of timeout, you will see that it is
easy to time code using Kernel.sleep. This is however very imprecise and
can’t be used for animation loops, for example.
b) EventMachine
require ‘eventmachine’
time = Time.now
EventMachine::add_timer(1) do
puts “hello one second from #{time}!”
end
Eventmachine should allow you to do more precise timing. Your
possibilities are of course limited by the system you run on.
greetings,
kaspar