module Sequel::TemporarilyReleaseConnection::PoolMethods

Public Instance Methods

temporarily_release_connection(conn, server) { || ... } click to toggle source

Temporarily release a currently checked out connection, then yield to the block. Reacquire the same connection upon the exit of the block.

# File lib/sequel/extensions/temporarily_release_connection.rb, line 74
def temporarily_release_connection(conn, server)
  t = Sequel.current
  raise Error, "connection not currently checked out" unless conn.equal?(trc_owned_connection(t, server))

  begin
    trc_release(t, conn, server)
    yield
  ensure
    c = trc_acquire(t, server)
    unless conn.equal?(c)
      raise UnableToReacquireConnectionError, "reacquired connection not the same as initial connection"
    end
  end
end