File: sleep_and_wait.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (14 lines) | stat: -rw-r--r-- 368 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Specs
  def self.sleep_and_wait_until(timeout = 10)
    t1 = Time.now.to_f
    ::Timeout.timeout(timeout) do
      loop until yield
    end

    diff = Time.now.to_f - t1
    STDERR.puts "wait took a bit long: #{diff} seconds" if diff > Specs::TIMER_QUANTUM
  rescue Timeout::Error
    t2 = Time.now.to_f
    raise "Timeout after: #{t2 - t1} seconds"
  end
end