Sha256: ed0375b45de440dbbd6c02dbfab3845eb721a5e614ba9f0c118c275bdd3ad0e4
Contents?: true
Size: 1.17 KB
Versions: 5
Compression:
Stored size: 1.17 KB
Contents
require 'sequel' require 'sequel/adapters/postgres' # Management of Postgres Sockets POSTGRES_SOCKETS = {} ## # Midori Extension of sequel postgres through meta programming class Sequel::Postgres::Adapter # Call a sql request asynchronously # @param [String] sql sql request # @param [Array] args args to send # @return [Array] sql query result def execute_query(sql, args) @db.log_connection_yield(sql, self, args) do if POSTGRES_SOCKETS[self].nil? POSTGRES_SOCKETS[self] = IO::open(socket) end socket_object = POSTGRES_SOCKETS[self] await(Promise.new do |resolve| count = 0 EventLoop.register(socket_object, :rw) do begin if (count == 0) # Writable unless is_busy send_query(sql) count += 1 end else # Readable EventLoop.deregister(socket_object) resolve.call(get_result) end # For extra errors # :nocov: rescue => e resolve.call(PromiseException.new(e)) # :nocov: end end end) end end end
Version data entries
5 entries across 5 versions & 1 rubygems