Class: Mysql2::Fibered::Client

Inherits:
Client
  • Object
show all
Defined in:
lib/active_record/connection_adapters/em_mysql2_adapter.rb

Defined Under Namespace

Modules: Watcher

Constant Summary

Constants inherited from Client

Client::CHARSET_MAP, Client::MYSQL_CHARSET_MAP

Instance Attribute Summary

Attributes inherited from Client

#query_options

Instance Method Summary collapse

Methods inherited from Client

#affected_rows, #async_result, #close, default_query_options, #encoding, encoding_from_charset, encoding_from_charset_code, #escape, escape, #info, #initialize, #last_id, #ping, #server_info, #socket, #thread_id

Constructor Details

This class inherits a constructor from Mysql2::Client

Instance Method Details

#query(sql, opts = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_record/connection_adapters/em_mysql2_adapter.rb', line 43

def query(sql, opts={})
  if ::EM.reactor_running?
    super(sql, opts.merge(:async => true))
    deferrable = ::EM::DefaultDeferrable.new
    ::EM.watch(self.socket, Watcher, self, deferrable).notify_readable = true
    fiber = Fiber.current
    deferrable.callback do |result|
      fiber.resume(result)
    end
    deferrable.errback do |err|
      fiber.resume(err)
    end
    Fiber.yield.tap do |result|
      raise result if result.is_a?(Exception)
    end
  else
    super(sql, opts)
  end
end