Class: SmartPolling
- Inherits:
-
Object
- Object
- SmartPolling
- Defined in:
- lib/smart_polling.rb,
lib/smart_polling/version.rb
Defined Under Namespace
Classes: TimeoutError
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Class Method Details
.poll(seconds: 10, delay: 1, timeout_error: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/smart_polling.rb', line 6 def self.poll(seconds: 10, delay: 1, timeout_error: nil) timeout_error ||= TimeoutError.new time_limit = Time.now + seconds while Time.now < time_limit do result = yield return result if result sleep delay end raise timeout_error end |