Sha256: e5e624ca4c00924bc6aeb571fbc3e69a97d76551bd28e9b2d990b38cb882a437

Contents?: true

Size: 816 Bytes

Versions: 42

Compression:

Stored size: 816 Bytes

Contents

# encoding: utf-8

require 'eventmachine'
require '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={})
        if ::EM.reactor_running?
          super(sql, opts.merge(:async => true))
          deferable = ::EM::DefaultDeferrable.new
          ::EM.watch(self.socket, Watcher, self, deferable).notify_readable = true
          deferable
        else
          super(sql, opts)
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 6 rubygems

Version Path
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/em.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/em.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/em.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/em.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/em.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/em.rb
mysql2-sp-0.3.10 lib/mysql2/em.rb
solaris-mysql2-0.3.11 lib/mysql2/em.rb
mysql2-0.3.11-x86-mswin32-60 lib/mysql2/em.rb
mysql2-0.3.11-x86-mingw32 lib/mysql2/em.rb
mysql2-0.3.11 lib/mysql2/em.rb
mysql2-0.2.18-x86-mswin32-60 lib/mysql2/em.rb
mysql2-0.2.18-x86-mingw32 lib/mysql2/em.rb
mysql2-0.2.18 lib/mysql2/em.rb
mysql2-0.3.10 lib/mysql2/em.rb
mysql2-0.2.17 lib/mysql2/em.rb
mysql2-0.2.16 lib/mysql2/em.rb
mysql2-0.3.9 lib/mysql2/em.rb
mysql2-0.2.16-x86-mswin32-60 lib/mysql2/em.rb
mysql2-0.2.16-x86-mingw32 lib/mysql2/em.rb