Sha256: c71d0cb51c5a67e1c3a961ea0f2d1fae326e91dd2404895373fbfb8634c9dc4e

Contents?: true

Size: 942 Bytes

Versions: 4

Compression:

Stored size: 942 Bytes

Contents

require 'connection_pool'
require 'oxblood/session'
require 'oxblood/pipeline'

module Oxblood
  class Pool
    # Initialize connection pool
    #
    # @param [Hash] options Connection options
    #
    # @option options [Float] :timeout (1.0) Connection acquisition timeout.
    # @option options [Integer] :size Pool size.
    # @option options [Hash] :connection see {Connection.open}
    def initialize(options = {})
      timeout = options.fetch(:timeout, 1.0)
      size = options.fetch(:size)

      @pool = ConnectionPool.new(size: size, timeout: timeout) do
        Connection.open(options.fetch(:connection, {}))
      end
    end

    def with
      conn = @pool.checkout
      yield Session.new(conn)
    ensure
      @pool.checkin if conn
    end

    def pipelined
      conn = @pool.checkout
      pipeline = Pipeline.new(conn)
      yield pipeline
      pipeline.sync
    ensure
      @pool.checkin if conn
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
oxblood-0.1.0.dev4 lib/oxblood/pool.rb
oxblood-0.1.0.dev3 lib/oxblood/pool.rb
oxblood-0.1.0.dev2 lib/oxblood/pool.rb
oxblood-0.1.0.dev1 lib/oxblood/pool.rb