andrea
andrea

Reputation: 381

EventMachine change delay in a periodic timer inside the block

Call a periodic timer and when an error occurs inside the block change this the periodic timer delay. Can i use periodic timer or the best way is an add_timer ?

Hi, i want to do this:

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

How to? Thanks

Upvotes: 0

Views: 1073

Answers (1)

Arkku
Arkku

Reputation: 42109

Create PeriodicTimer object yourself, and call its accessor interval= to set the interval:

EventMachine.run do
  timer = EventMachine::PeriodicTimer.new(1) do
    puts "Timer fired at #{Time.now}"
  end
  # timer.interval = 1
  # timer.interval = 20
end

Upvotes: 1

Related Questions