lib/evdispatch/loop.rb in evdispatch-0.2.2 vs lib/evdispatch/loop.rb in evdispatch-0.2.4
- old
+ new
@@ -2,24 +2,16 @@
# 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 )
+ def response(id, timeout = 1.0)
+ timer = Time.now
+ while wait_for_response( id, 1, 0 )
res = response_for( id )
break if res
- attempts += 1
- #puts "Attempt: #{attempts}"
+ break if( (Time.now - timer) > timeout )
end
- return nil if !res and attempts == max_attempts
res = response_for( id ) unless res
res
end
end
end