Class: Nanite::Reaper

Inherits:
Object show all
Defined in:
lib/nanite/reaper.rb

Instance Method Summary collapse

Constructor Details

#initialize(frequency = 2) ⇒ Reaper

Returns a new instance of Reaper.



4
5
6
7
# File 'lib/nanite/reaper.rb', line 4

def initialize(frequency=2)
  @timeouts = {}
  EM.add_periodic_timer(frequency) { EM.next_tick { reap } }
end

Instance Method Details

#reset(token) ⇒ Object



13
14
15
# File 'lib/nanite/reaper.rb', line 13

def reset(token)
  @timeouts[token][:timestamp] = Time.now + @timeouts[token][:seconds]
end

#timeout(token, seconds, &blk) ⇒ Object



9
10
11
# File 'lib/nanite/reaper.rb', line 9

def timeout(token, seconds, &blk)
  @timeouts[token] = {:timestamp => Time.now + seconds, :seconds => seconds, :callback => blk}
end