Class: Klomp::Sentinel
- Inherits:
-
Object
- Object
- Klomp::Sentinel
- Defined in:
- lib/klomp/sentinel.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(connection) ⇒ Sentinel
constructor
A new instance of Sentinel.
- #run ⇒ Object
Constructor Details
#initialize(connection) ⇒ Sentinel
Returns a new instance of Sentinel.
3 4 5 6 |
# File 'lib/klomp/sentinel.rb', line 3 def initialize(connection) @connection = connection @thread = Thread.new { run } unless @connection.connected? end |
Instance Method Details
#alive? ⇒ Boolean
8 9 10 |
# File 'lib/klomp/sentinel.rb', line 8 def alive? @thread && @thread.alive? end |
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/klomp/sentinel.rb', line 12 def run fib_state = [0, 1] loop do begin @connection.reconnect break rescue sleep fib_state[1] fib_state = [fib_state[1], fib_state[0]+fib_state[1]] end end end |