Sha256: b01b338a4563b24f5272fd7fffa811facec80274d20c5247f3bad4d5710a667f

Contents?: true

Size: 1.1 KB

Versions: 31

Compression:

Stored size: 1.1 KB

Contents

require 'eventmachine'
require 'mysql2'

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

        def notify_readable
          detach
          begin
            result = @client.async_result
          rescue StandardError => e
            @deferable.fail(e)
          else
            @deferable.succeed(result)
          end
        end

        def watching?
          @is_watching
        end

        def unbind
          @is_watching = false
        end
      end

      def close(*args)
        @watch.detach if @watch && @watch.watching?

        super(*args)
      end

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

Version data entries

31 entries across 30 versions & 4 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.6/lib/mysql2/em.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/mysql2-0.5.6/lib/mysql2/em.rb
mysql2-0.5.6 lib/mysql2/em.rb
mysql2-0.5.5 lib/mysql2/em.rb
mysql2-0.5.4 lib/mysql2/em.rb
mysql2-lambda-0.5.3.2 ./lib/mysql2/em.rb
mysql2-lambda-0.5.3.1 ./lib/mysql2/em.rb
mysql2-lambda-0.5.3.0 ./lib/mysql2/em.rb
mysql2-lambda-0.5.3.beta.2 ./lib/mysql2/em.rb
mysql2-lambda-0.5.3.beta.1 ./lib/mysql2/em.rb
mysql2-lambda-0.5.3.alpha1 ./lib/mysql2/em.rb
mysql2-lambda-test-0.5.3.test4 lib/mysql2/em.rb
mysql2-lambda-test-0.5.3.test3 lib/mysql2/em.rb
mysql2-lambda-test-0.5.3.test2 lib/mysql2/em.rb
mysql2-lambda-test-0.5.3.test1 lib/mysql2/em.rb
mysql2-0.5.3-x64-mingw32 lib/mysql2/em.rb
mysql2-0.5.3-x86-mingw32 lib/mysql2/em.rb
mysql2-0.5.3-x86-mswin32-60 lib/mysql2/em.rb
mysql2-0.5.3 lib/mysql2/em.rb
mysql2-0.5.2-x64-mingw32 lib/mysql2/em.rb