Sha256: 43176927ed32ec24c9a9031cf0ba81e89a9ea76d7f5f153e71048b304c47ecdd
Contents?: true
Size: 1 KB
Versions: 13
Compression:
Stored size: 1 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) && const_get(:Timeout) || ::Timeout::Error end def wait_for(timeout = self.timeout, interval = 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 = poll_interval, &block) wait_for(timeout, interval, &block) || fail(timeout_error, "wait_for(#{timeout}) exceeded") end end end
Version data entries
13 entries across 13 versions & 1 rubygems