if no reactor use synch query
This commit is contained in:
parent
9d49728c30
commit
dac2f02c9b
@ -23,10 +23,14 @@ module Mysql2
|
||||
end
|
||||
|
||||
def query(sql, opts={})
|
||||
super(sql, opts.merge(:async => true))
|
||||
deferable = ::EM::DefaultDeferrable.new
|
||||
::EM.watch(self.socket, Watcher, self, deferable).notify_readable = true
|
||||
deferable
|
||||
if ::EM.reactor_running?
|
||||
super(sql, opts.merge(:async => true))
|
||||
deferable = ::EM::DefaultDeferrable.new
|
||||
::EM.watch(self.socket, Watcher, self, deferable).notify_readable = true
|
||||
deferable
|
||||
else
|
||||
super(sql, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,23 +1,28 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require 'mysql2/em'
|
||||
require 'fiber' unless defined? Fiber
|
||||
require 'fiber'
|
||||
|
||||
module Mysql2
|
||||
module EM
|
||||
module Fiber
|
||||
class Client < ::Mysql2::EM::Client
|
||||
def query(sql, opts={})
|
||||
deferable = super(sql, opts)
|
||||
if ::EM.reactor_running?
|
||||
deferable = super(sql, opts)
|
||||
|
||||
fiber = ::Fiber.current
|
||||
deferable.callback do |result|
|
||||
fiber.resume(result)
|
||||
fiber = ::Fiber.current
|
||||
deferable.callback do |result|
|
||||
fiber.resume(result)
|
||||
end
|
||||
deferable.errback do |err|
|
||||
p err
|
||||
fiber.resume(err)
|
||||
end
|
||||
::Fiber.yield
|
||||
else
|
||||
super(sql, opts)
|
||||
end
|
||||
deferable.errback do |err|
|
||||
fiber.resume(err)
|
||||
end
|
||||
::Fiber.yield
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user