Sha256: 35186354e73475831aff31f47fd93348e44397837e9217d1e0a1085caf8747ee

Contents?: true

Size: 775 Bytes

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
mysql2-0.2.4 lib/mysql2/em.rb
mysql2-0.2.3 lib/mysql2/em.rb
mysql2-0.2.2 lib/mysql2/em.rb
mysql2-0.2.1 lib/mysql2/em.rb
mysql2-0.2.0 lib/mysql2/em.rb
mysql2-0.1.9 lib/mysql2/em.rb
mysql2-0.1.8 lib/mysql2/em.rb
mysql2-0.1.7 lib/mysql2/em.rb
mysql2-0.1.6 lib/mysql2/em.rb
mysql2-0.1.5 lib/mysql2/em.rb
mysql2-0.1.4 lib/mysql2/em.rb
mysql2-0.1.3 lib/mysql2/em.rb