class Async::Postgres::Connection

Public Class Methods

new(connection_string, reactor = nil) click to toggle source
Calls superclass method
# File lib/async/postgres/connection.rb, line 28
def initialize(connection_string, reactor = nil)
        @connection = PG::Connection.connect_start(connection_string)
        
        super(@connection.socket_io, reactor)
        
        status = @connection.connect_poll
        
        while true
                if status == PG::PGRES_POLLING_FAILED
                        raise PG::Error.new(@connection.error_message)
                elsif status == PG::PGRES_POLLING_READING
                        self.wait_readable
                elsif(status == PG::PGRES_POLLING_WRITING)
                        self.wait_writable
                elsif status == PG::PGRES_POLLING_OK
                        break
                end
                
                status = @connection.connect_poll
        end
end

Public Instance Methods

async_exec(*args) { |result| ... } click to toggle source
# File lib/async/postgres/connection.rb, line 50
def async_exec(*args)
        @connection.send_query(*args)
        last_result = result = true
        
        while true
                wait_readable
                
                @connection.consume_input
                
                while @connection.is_busy == false
                        if result = @connection.get_result
                                last_result = result
                                
                                yield result if block_given?
                        else
                                return last_result
                        end
                end
        end
ensure
        @connection.get_result until result.nil?
end
Also aliased as: exec
exec(*args)
Also aliased as: exec_params
Alias for: async_exec
exec_params(*args)
Alias for: exec
method_missing(*args) click to toggle source
# File lib/async/postgres/connection.rb, line 80
def method_missing(*args)
        @connection.send(*args)
end
respond_to?(*args) click to toggle source
# File lib/async/postgres/connection.rb, line 76
def respond_to?(*args)
        @connection.respond_to(*args)
end