Class: Sync::EM::PG::Sequel::ConnectionPool

Inherits:
Sequel::ConnectionPool
  • Object
show all
Defined in:
lib/sync-em/pg/sequel.rb

Constant Summary collapse

DEFAULT_SIZE =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, opts = {}) ⇒ ConnectionPool

Returns a new instance of ConnectionPool.



33
34
35
36
37
38
39
# File 'lib/sync-em/pg/sequel.rb', line 33

def initialize(db, opts = {})
  super
  size = opts[:max_connection] || DEFAULT_SIZE
  @pool = ReConnectionPool.new(size: size) do
    make_new(DEFAULT_SERVER)
  end
end

Instance Attribute Details

#poolObject

Returns the value of attribute pool.



32
33
34
# File 'lib/sync-em/pg/sequel.rb', line 32

def pool
  @pool
end

Instance Method Details

#disconnect(server = nil) ⇒ Object



49
50
51
52
# File 'lib/sync-em/pg/sequel.rb', line 49

def disconnect(server = nil)
  @pool.available.each{ |conn| db.disconnect_connection(conn) }
  @pool.available.clear
end

#hold(server = nil, &blk) ⇒ Object



45
46
47
# File 'lib/sync-em/pg/sequel.rb', line 45

def hold(server = nil, &blk)
  @pool.execute(false, &blk)
end

#sizeObject



41
42
43
# File 'lib/sync-em/pg/sequel.rb', line 41

def size
  @pool.available.size
end