Class: Raft::Timer

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

Instance Method Summary collapse

Constructor Details

#initialize(interval, splay = 0.0) ⇒ Timer

Returns a new instance of Timer.



148
149
150
151
152
# File 'lib/raft.rb', line 148

def initialize(interval, splay=0.0)
  @interval = interval.to_f
  @splay = splay.to_f
  @start = Time.now - @interval + (rand * @splay)
end

Instance Method Details

#reset!Object



158
159
160
161
# File 'lib/raft.rb', line 158

def reset!
  @start = Time.now + splayed_interval
  #STDOUT.write("\ntimer will elapse at #{timeout.strftime('%H:%M:%S:%L')} (timeout is #{timeout.class})\n")
end

#splayed_intervalObject



154
155
156
# File 'lib/raft.rb', line 154

def splayed_interval
  (@interval + (rand * @splay))#.tap {|t|STDOUT.write("\nsplayed interval is #{t}\n")}
end

#timed_out?Boolean

Returns:

  • (Boolean)


167
168
169
170
# File 'lib/raft.rb', line 167

def timed_out?
  #STDOUT.write("\ntime is #{Time.now.strftime('%M:%S:%L')}\n")
  Time.now > timeout
end

#timeoutObject



163
164
165
# File 'lib/raft.rb', line 163

def timeout
  @start + @interval
end