Sha256: ecff76cfed6a4cbf589ad1c50b8c04e5b24a193638014180b694e656f50889b9

Contents?: true

Size: 1007 Bytes

Versions: 6

Compression:

Stored size: 1007 Bytes

Contents

begin
  require 'mysql2/em'
rescue LoadError => error
  raise 'Missing EM-Synchrony dependency: gem install mysql2'
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) }

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
em-synchrony-1.0.6 lib/em-synchrony/mysql2.rb
em-synchrony-1.0.5 lib/em-synchrony/mysql2.rb
em-synchrony-1.0.4 lib/em-synchrony/mysql2.rb
em-synchrony-1.0.3 lib/em-synchrony/mysql2.rb
em-synchrony-1.0.2 lib/em-synchrony/mysql2.rb
em-synchrony-1.0.1 lib/em-synchrony/mysql2.rb