Module: Tenable::Pollable
- Included in:
- Resources::Base
- Defined in:
- lib/tenable/pollable.rb
Overview
Shared polling behavior for resources that need to wait on async operations.
Uses monotonic clock to avoid issues with system clock changes.
Instance Method Summary collapse
-
#poll_until(timeout:, poll_interval:, label:) { ... } ⇒ Object
Polls a block until it returns a truthy value or the timeout expires.
Instance Method Details
#poll_until(timeout:, poll_interval:, label:) { ... } ⇒ Object
Polls a block until it returns a truthy value or the timeout expires.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tenable/pollable.rb', line 17 def poll_until(timeout:, poll_interval:, label:) deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout loop do if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline raise Tenable::TimeoutError, "#{label} timed out after #{timeout}s" end result = yield return result if result sleep(poll_interval) end end |