def send(wait=false, ttl=nil, &block)
if wait
message = nil
blockedThread = Thread.current
timer_thread = nil
timeout = false
unless ttl.nil?
timer_thread = Thread.new {
sleep ttl
timeout = true
blockedThread.wakeup
}
end
@session.connection.send(self.to_s, block) do |je|
if je.element_tag == "message" and je.thread.element_data == @thread
je.consume_element
message = Message.from_element(@session, je)
blockedThread.wakeup unless timeout
unless timer_thread.nil?
timer_thread.kill
timer_thread = nil
end
end
end
Thread.stop
return message
else
@session.connection.send(self.to_s, block) if @session
end
end