Class: Ratomic::Pool

Inherits:
FixedSizeObjectPool
  • Object
show all
Defined in:
lib/ratomic.rb

Instance Method Summary collapse

Constructor Details

#initialize(size = 5, timeout = 1.0) ⇒ Pool

Returns a new instance of Pool.



36
37
38
# File 'lib/ratomic.rb', line 36

def initialize(size = 5, timeout = 1.0)
  super(size, (timeout * 1000).to_i)
end

Instance Method Details

#withObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ratomic.rb', line 40

def with
  obj_and_idx = checkout
  if obj_and_idx.nil?
    raise Ratomic::Error, "pool checkout timeout"
  else
    yield obj_and_idx[0]
  end
ensure
  unless obj_and_idx.nil?
    checkin(obj_and_idx[1])
  end
end