Class: Sequel::FiberedConnectionPool

Inherits:
ConnectionPool show all
Defined in:
lib/sequel/extensions/fibered_connection_pool.rb

Instance Method Summary collapse

Methods included from ConnectionPoolPatch

#connection_pool_class

Constructor Details

#initialize(db, opts = Sequel::OPTS) ⇒ FiberedConnectionPool

Returns a new instance of FiberedConnectionPool.



7
8
9
10
11
12
13
14
# File 'lib/sequel/extensions/fibered_connection_pool.rb', line 7

def initialize(db, opts = Sequel::OPTS)
  super(db, opts)

  @max_connections = opts[:max_connections]
  @available_connections = []
  @notification = Async::Notification.new
  @size = 0
end

Instance Method Details

#disconnectObject



37
38
39
40
41
42
# File 'lib/sequel/extensions/fibered_connection_pool.rb', line 37

def disconnect(*)
  @available_connections.each(&:close)
  @available_connections.clear

  @size = 0
end

#holdObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sequel/extensions/fibered_connection_pool.rb', line 16

def hold(*)
  connection = wait_for_connection
  return connection unless block_given?

  begin
    yield connection
  rescue Sequel::DatabaseDisconnectError, *@error_classes => error
    if disconnect_error?(error)
      disconnect_connection(connection)
      connection = nil
      @size -= 1
    end
    raise
  ensure
    if connection
      @available_connections.push(connection)
      @notification.signal if Async::Task.current?
    end
  end
end

#sizeObject



44
45
46
# File 'lib/sequel/extensions/fibered_connection_pool.rb', line 44

def size
  @size
end