class UniqueThread::Stopwatch
Attributes
downtime[R]
Public Class Methods
new(downtime:)
click to toggle source
# File lib/unique_thread/stopwatch.rb, line 7 def initialize(downtime:) @downtime = downtime.to_f end
Public Instance Methods
next_renewal()
click to toggle source
# File lib/unique_thread/stopwatch.rb, line 15 def next_renewal now + (downtime * 2 / 3) end
now()
click to toggle source
# File lib/unique_thread/stopwatch.rb, line 11 def now Time.now.to_f end
sleep_until_next_attempt(locked_until)
click to toggle source
# File lib/unique_thread/stopwatch.rb, line 19 def sleep_until_next_attempt(locked_until) seconds_until_next_attempt = [locked_until - now + Random.new.rand(downtime / 3), 0].max Kernel.sleep(seconds_until_next_attempt) end
sleep_until_renewal_attempt()
click to toggle source
# File lib/unique_thread/stopwatch.rb, line 25 def sleep_until_renewal_attempt Kernel.sleep(downtime / 3) end