lib/em-synchrony/mysql2.rb in em-synchrony-1.0.0 vs lib/em-synchrony/mysql2.rb in em-synchrony-1.0.1
- old
+ new
@@ -5,13 +5,29 @@
end
module Mysql2
module EM
class Client
+ module Watcher
+ def notify_readable
+ detach
+ begin
+ result = @client.async_result
+ rescue Exception => e
+ @deferable.fail(e)
+ else
+ @deferable.succeed(result)
+ end
+ end
+ end
alias :aquery :query
def query(sql, opts={})
deferable = aquery(sql, opts)
+
+ # if EM is not running, we just get the sql result directly
+ # if we get a deferable, then let's do the deferable thing.
+ return deferable unless deferable.kind_of? ::EM::DefaultDeferrable
f = Fiber.current
deferable.callback { |res| f.resume(res) }
deferable.errback { |err| f.resume(err) }