Class: Soren::Deadline
Class Method Summary collapse
-
.start(timeout) ⇒ Object
: (Float?) -> Soren::Deadline?.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
: -> bool.
-
#initialize(deadline_at) ⇒ Deadline
constructor
: (Float) -> void.
-
#remaining ⇒ Object
: -> Float.
Constructor Details
#initialize(deadline_at) ⇒ Deadline
: (Float) -> void
16 17 18 |
# File 'lib/soren/deadline.rb', line 16 def initialize(deadline_at) @deadline_at = deadline_at #: Float end |
Class Method Details
.start(timeout) ⇒ Object
: (Float?) -> Soren::Deadline?
8 9 10 11 12 |
# File 'lib/soren/deadline.rb', line 8 def start(timeout) return unless timeout new(Process.clock_gettime(Process::CLOCK_MONOTONIC).to_f + timeout) end |
Instance Method Details
#expired? ⇒ Boolean
: -> bool
27 28 29 |
# File 'lib/soren/deadline.rb', line 27 def expired? remaining <= 0 end |
#remaining ⇒ Object
: -> Float
21 22 23 24 |
# File 'lib/soren/deadline.rb', line 21 def remaining time = @deadline_at - Process.clock_gettime(Process::CLOCK_MONOTONIC) time > 0 ? time : 0.0 end |