Class: TCPSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/tcp_socket_extension.rb

Class Method Summary collapse

Class Method Details

.wait_for_service(options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tcp_socket_extension.rb', line 6

def self.wait_for_service(options)
  socket = nil
  Timeout::timeout(options[:timeout] || 20) do
    loop do
      begin
        socket = TCPSocket.new(options[:host], options[:port])
        return
      rescue Errno::ECONNREFUSED
        puts ".\n"
        sleep 2
      end
    end
  end
ensure
  socket.close unless socket.nil?
end