Sha256: a0480b44a1a5b5226fb55341ef043a074124187d2508144b62a24f5a2438f685

Contents?: true

Size: 995 Bytes

Versions: 28

Compression:

Stored size: 995 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
            result = @client.async_result
          rescue Exception => e
            @deferable.fail(e)
          else
            @deferable.succeed(result)
          end
        end
      end

      def close(*args)
        if @watch
          @watch.detach
        end
        super(*args)
      end

      def query(sql, opts={})
        if ::EM.reactor_running?
          super(sql, opts.merge(:async => true))
          deferable = ::EM::DefaultDeferrable.new
          @watch = ::EM.watch(self.socket, Watcher, self, deferable)
          @watch.notify_readable = true
          deferable
        else
          super(sql, opts)
        end
      end
    end
  end
end

Version data entries

28 entries across 25 versions & 2 rubygems

Version Path
mysql2-0.2.24 lib/mysql2/em.rb
mysql2-0.3.17 lib/mysql2/em.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/mysql2-0.3.16/lib/mysql2/em.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.16/lib/mysql2/em.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/mysql2-0.3.16/lib/mysql2/em.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.16/lib/mysql2/em.rb
mysql2-0.3.16 lib/mysql2/em.rb
mysql2-0.2.23 lib/mysql2/em.rb
mysql2-0.3.15 lib/mysql2/em.rb
mysql2-0.2.22 lib/mysql2/em.rb
mysql2-0.2.21 lib/mysql2/em.rb
mysql2-0.3.14 lib/mysql2/em.rb
mysql2-0.3.13 lib/mysql2/em.rb
mysql2-0.2.20 lib/mysql2/em.rb
mysql2-0.3.12 lib/mysql2/em.rb
mysql2-0.2.19 lib/mysql2/em.rb
mysql2-0.3.12b6 lib/mysql2/em.rb
mysql2-0.2.19b6 lib/mysql2/em.rb
mysql2-0.2.19b5 lib/mysql2/em.rb
mysql2-0.3.12b5 lib/mysql2/em.rb