Class: EventMachine::PeriodicTimer

Inherits:
Object
  • Object
show all
Defined in:
lib/eventmachine.rb

Overview

TODO, document this

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ PeriodicTimer

Returns a new instance of PeriodicTimer.



1865
1866
1867
1868
1869
# File 'lib/eventmachine.rb', line 1865

def initialize *args, &block
  @interval = args.shift
  @code = args.shift || block
  schedule
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



1864
1865
1866
# File 'lib/eventmachine.rb', line 1864

def interval
  @interval
end

Instance Method Details

#cancelObject



1879
1880
1881
# File 'lib/eventmachine.rb', line 1879

def cancel
  @cancelled = true
end

#fireObject



1873
1874
1875
1876
1877
1878
# File 'lib/eventmachine.rb', line 1873

def fire
  unless @cancelled
    @code.call
    schedule
  end
end

#scheduleObject



1870
1871
1872
# File 'lib/eventmachine.rb', line 1870

def schedule
  EventMachine::add_timer @interval, proc {self.fire}
end