2013-11-22 51 views
0

调用周期性定时器,当块内发生错误时,更改此周期性定时器延迟。我可以使用定期计时器还是最好的方法是add_timer?EventMachine更改块内周期性定时器的延迟

嗨,我想这样做:

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 

如何? 感谢

回答

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 
+0

是的,我已经找到了一些分钟前! http://eventmachine.rubyforge.org/EventMachine/PeriodicTimer.html#interval-instance_method谢谢! – andrea

相关问题