Class: SingleThreadedPool

Class | SingleThreadedPool
In: | lib/assistance/connection_pool.rb
Parent: | Object

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.

### Methods

disconnect hold new

### Attributes

conn | [R] |
connection_proc | [W] |

### Public Class methods

new(&block)

Initializes the instance with the supplied block as the connection_proc.

[Source]

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

### Public Instance methods

disconnect(&block)

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

[Source]

         # File lib/assistance/connection_pool.rb, line 146
    146:   def disconnect(&block)
    147:     block[@conn] if block && @conn
    148:     @conn = nil
    149:   end

hold() {|@conn| ...}

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

[Source]

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

[Validate]