Class: Mysql2::EM::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/em-synchrony/mysql2.rb

Defined Under Namespace

Modules: Watcher

Instance Method Summary collapse

Instance Method Details

#aqueryObject


23
# File 'lib/em-synchrony/mysql2.rb', line 23

alias :aquery :query

#query(sql, opts = {}) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/em-synchrony/mysql2.rb', line 24

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) }

  Fiber.yield.tap do |result|
    raise result if result.is_a?(::Exception)
  end
end