Module: Ferrum::Utils::Poll
- Defined in:
- lib/ferrum/utils/poll.rb,
sig/ferrum/utils/poll.rbs
Overview
The loop behind every wait_* method: runs a block until it returns a
truthy value or the timeout is reached, sleeping between the attempts.
Class Method Summary collapse
-
.attempt(deadline) { ... } ⇒ Object?
Runs the block once, turning a TimeoutError it raises into
nilonce the deadline has expired. -
.call(timeout, interval) { ... } ⇒ Object?
Runs the block until it returns a truthy value.
Class Method Details
.attempt(deadline) { ... } ⇒ Object?
Runs the block once, turning a TimeoutError it raises into nil
once the deadline has expired.
48 49 50 51 52 53 54 |
# File 'lib/ferrum/utils/poll.rb', line 48 def attempt(deadline) yield rescue TimeoutError raise unless deadline.expired? nil end |
.call(timeout, interval) { ... } ⇒ Object?
Runs the block until it returns a truthy value. Calls in the block share the timeout, see Deadline.within.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ferrum/utils/poll.rb', line 27 def call(timeout, interval, &) deadline = Deadline.wrap(timeout) Deadline.within(deadline) do loop do value = attempt(deadline, &) return value if value return if deadline.expired? sleep([interval, deadline.remaining].min) end end end |