Class: Mysql2::EM::Fiber::Client

Inherits:
Client show all
Defined in:
lib/mysql2/em_fiber.rb

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mysql2/em_fiber.rb', line 10

def query(sql, opts={})
  if ::EM.reactor_running?
    deferable = super(sql, opts)

    fiber = ::Fiber.current
    deferable.callback do |result|
      fiber.resume(result)
    end
    deferable.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