Module: Ferrum::Utils::ElapsedTime
- Defined in:
- lib/ferrum/utils/elapsed_time.rb
Overview
A monotonic-clock helper for tracking elapsed time and checking
timeouts, backed by Concurrent.monotonic_time.
Class Method Summary collapse
-
.elapsed_time(start = nil) ⇒ Float
Returns the time elapsed since
start(or since ElapsedTime.start/ElapsedTime.reset was called). -
.monotonic_time ⇒ Float
Returns the current monotonic clock time in seconds.
-
.reset ⇒ Float
Resets the start point to the current monotonic time.
-
.start ⇒ Float
Sets the start point to the current monotonic time unless already set.
-
.timeout?(start, timeout) ⇒ Boolean
Whether more than
timeoutseconds have elapsed sincestart.
Class Method Details
.elapsed_time(start = nil) ⇒ Float
38 39 40 |
# File 'lib/ferrum/utils/elapsed_time.rb', line 38 def elapsed_time(start = nil) monotonic_time - (start || @start) end |
.monotonic_time ⇒ Float
Returns the current monotonic clock time in seconds.
47 48 49 |
# File 'lib/ferrum/utils/elapsed_time.rb', line 47 def monotonic_time Concurrent.monotonic_time end |
.reset ⇒ Float
Resets the start point to the current monotonic time.
26 27 28 |
# File 'lib/ferrum/utils/elapsed_time.rb', line 26 def reset @start = monotonic_time end |
.start ⇒ Float
Sets the start point to the current monotonic time unless already set.
17 18 19 |
# File 'lib/ferrum/utils/elapsed_time.rb', line 17 def start @start ||= monotonic_time end |
.timeout?(start, timeout) ⇒ Boolean
Whether more than timeout seconds have elapsed since start.
62 63 64 |
# File 'lib/ferrum/utils/elapsed_time.rb', line 62 def timeout?(start, timeout) elapsed_time(start) > timeout end |