Module: Kernel
- Defined in:
- lib/smartfox_jruby/common.rb
Defined Under Namespace
Classes: WaitTimeoutException
Instance Method Summary collapse
Instance Method Details
#wait_with_timeout(timeout = 20, opts = {:sleep_time => 0.1}) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/smartfox_jruby/common.rb', line 132 def wait_with_timeout(timeout = 20, opts = {:sleep_time => 0.1}) timeout ||= 20 raise "Block is required!" unless block_given? time = Time.now.to_i finished = false while (Time.now.to_i < time + timeout) && !finished sleep opts[:sleep_time] || 0.01 # sleep for 10 ms to wait the response finished = yield end raise WaitTimeoutException.new("Timeout while waiting!") unless finished end |