Sha256: 73b19e1fa0fe69f49300d9e6b6238ae3aedd7a69c0a50b2b8dfa3f8c1ecd6ecc
Contents?: true
Size: 1.02 KB
Versions: 35
Compression:
Stored size: 1.02 KB
Contents
require 'timeout' module Cistern module WaitFor def timeout @timeout || Cistern.timeout end def timeout=(timeout) @timeout = timeout end def poll_interval @poll_interval || Cistern.poll_interval end def poll_interval=(poll_interval) @poll_interval = poll_interval end def timeout_error=(timeout_error) @timeout_error = timeout_error end def timeout_error @timeout_error || self.const_defined?(:Timeout) && self.const_get(:Timeout) || ::Timeout::Error end def wait_for(timeout = self.timeout, interval = self.poll_interval, &block) duration = 0 start = Time.now until yield || duration > timeout sleep(interval.to_f) duration = Time.now - start end duration > timeout ? false : duration end def wait_for!(timeout = self.timeout, interval = self.poll_interval, &block) wait_for(timeout, interval, &block) || raise(timeout_error, "wait_for(#{timeout}) exceeded") end end end
Version data entries
35 entries across 35 versions & 1 rubygems