Class: Appom::Wait
- Inherits:
-
Object
- Object
- Appom::Wait
- Defined in:
- lib/appom/wait.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
5
- DEFAULT_INTERVAL =
0.25
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Wait
constructor
Create a new Wait instance.
-
#until ⇒ Object
Wait until the given block returns a true value.
Constructor Details
#initialize(opts = {}) ⇒ Wait
Create a new Wait instance
13 14 15 16 |
# File 'lib/appom/wait.rb', line 13 def initialize(opts = {}) @timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT) @interval = opts.fetch(:interval, DEFAULT_INTERVAL) end |
Instance Method Details
#until ⇒ Object
Wait until the given block returns a true value.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/appom/wait.rb', line 24 def until end_time = Time.now + @timeout until Time.now > end_time begin result = yield return result if result rescue end sleep @interval end raise Appom::TimeoutError, "Timed out after #{@timeout}s." end |