调用周期性定时器,当块内发生错误时,改变定期定时器延迟。我可以使用定期计时器,还是最好的方法是add_timer?
嗨,我想这样做:
EventMachine.run
EventMachine.add_periodic_timer 1
//read from a input
//if error set timer to 20s
//if ok set timer to 1s
end
end
怎么样? 感谢
答案 0 :(得分:1)
自己创建PeriodicTimer
个对象,并调用其访问者interval=
来设置间隔:
EventMachine.run do
timer = EventMachine::PeriodicTimer.new(1) do
puts "Timer fired at #{Time.now}"
end
# timer.interval = 1
# timer.interval = 20
end