require 'revdispatch' # define this part in ruby to make sure other # ruby threads can execute while we waiting for a response module Evdispatch class Loop def response(id, timeout = 1.0, max_attempts = 100) attempts = 0 ms = timeout * 1000 # convert to miliseconds ms_i = ms.to_i seconds = ms_i / 1000 mseconds = (ms - (seconds*1000)).to_i #puts "Waiting #{seconds} seconds and #{mseconds} miliseconds" while (wait_for_response( id, seconds, mseconds ) and attempts < max_attempts ) res = response_for( id ) break if res attempts += 1 #puts "Attempt: #{attempts}" end return nil if !res and attempts == max_attempts res = response_for( id ) unless res res end end end