Module: Probatio::Waiters

Included in:
Context, Section
Defined in:
lib/probatio/waiters.rb

Overview

probatio/waiters.rb

Instance Method Summary collapse

Instance Method Details

#monowObject



29
30
31
32
# File 'lib/probatio/waiters.rb', line 29

def monow

  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

#wait_until(opts = {}, &block) ⇒ Object Also known as: wait_for



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/probatio/waiters.rb', line 7

def wait_until(opts={}, &block)

  timeout = opts[:timeout] || 14
  frequency = opts[:frequency] || 0.1

  start = Probatio.monow

  loop do

    sleep(frequency)

    #return if block.call == true
    r = block.call
    return r if r

    break if Probatio.monow - start > timeout
  end

  fail "timeout after #{timeout}s"
end