Parent

SingleThreadedPool

A SingleThreadedPool acts as a replacement for a ConnectionPool for use in single-threaded applications. ConnectionPool imposes a substantial performance penalty, so SingleThreadedPool is used to gain some speed.

Attributes

conn[R]
connection_proc[W]

Public Class Methods

new(&block) click to toggle source

Initializes the instance with the supplied block as the connection_proc.

# File lib/assistance/connection_pool.rb, line 130
def initialize(&block)
  @connection_proc = block
end

Public Instance Methods

disconnect(&block) click to toggle source

Disconnects from the database. Once a connection is requested using hold, the connection is reestablished.

# File lib/assistance/connection_pool.rb, line 146
def disconnect(&block)
  block[@conn] if block && @conn
  @conn = nil
end
hold() click to toggle source

Yields the connection to the supplied block. This method simulates the ConnectionPool#hold API.

# File lib/assistance/connection_pool.rb, line 136
def hold
  @conn ||= @connection_proc.call
  yield @conn
rescue Exception => e
  # if the error is not a StandardError it is converted into RuntimeError.
  raise e.is_a?(StandardError) ? e : e.message
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.