Sha256: da282ae9c33f6e4f7181bc753ca215a63281e12e14fd656c73c79b0f934c1ad9

Contents?: true

Size: 775 Bytes

Versions: 4

Compression:

Stored size: 775 Bytes

Contents

# encoding: utf-8

require 'eventmachine' unless defined? EventMachine
require 'mysql2' unless defined? Mysql2

module Mysql2
  module EM
    class Client < ::Mysql2::Client
      module Watcher
        def initialize(client, deferable)
          @client = client
          @deferable = deferable
        end

        def notify_readable
          detach
          begin
            @deferable.succeed(@client.async_result)
          rescue Exception => e
            @deferable.fail(e)
          end
        end
      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
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mysql2-0.2.6 lib/mysql2/em.rb
mysql2-0.2.6-x86-mswin32-60 lib/mysql2/em.rb
mysql2-0.2.6-x86-mingw32 lib/mysql2/em.rb
mysql2-0.2.5 lib/mysql2/em.rb