fall back to blocking behavior for em_mysql2 AR adapter if EM isn't running
This commit is contained in:
parent
3ec92096ca
commit
678ff1cee9
@ -42,17 +42,21 @@ module Mysql2
|
|||||||
end
|
end
|
||||||
|
|
||||||
def query(sql, opts={})
|
def query(sql, opts={})
|
||||||
super(sql, opts.merge(:async => true))
|
if EM.reactor_running?
|
||||||
deferable = ::EM::DefaultDeferrable.new
|
super(sql, opts.merge(:async => true))
|
||||||
::EM.watch(self.socket, Watcher, self, deferable).notify_readable = true
|
deferable = ::EM::DefaultDeferrable.new
|
||||||
fiber = Fiber.current
|
::EM.watch(self.socket, Watcher, self, deferable).notify_readable = true
|
||||||
deferable.callback do |result|
|
fiber = Fiber.current
|
||||||
fiber.resume(result)
|
deferable.callback do |result|
|
||||||
|
fiber.resume(result)
|
||||||
|
end
|
||||||
|
deferable.errback do |err|
|
||||||
|
fiber.resume(err)
|
||||||
|
end
|
||||||
|
Fiber.yield
|
||||||
|
else
|
||||||
|
super(sql, opts)
|
||||||
end
|
end
|
||||||
deferable.errback do |err|
|
|
||||||
fiber.resume(err)
|
|
||||||
end
|
|
||||||
Fiber.yield
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user