Class: Mysql2::Fibered::Client
- Inherits:
-
Client
- Object
- Client
- Mysql2::Fibered::Client
- Defined in:
- lib/active_record/connection_adapters/em_mysql2_adapter.rb
Defined Under Namespace
Modules: Watcher
Instance Method Summary collapse
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 |