Class: Litesupport::Pool
- Inherits:
-
Object
- Object
- Litesupport::Pool
- Defined in:
- lib/litestack/litesupport.rb
Instance Method Summary collapse
- #acquire ⇒ Object
-
#initialize(count, &block) ⇒ Pool
constructor
A new instance of Pool.
Constructor Details
#initialize(count, &block) ⇒ Pool
Returns a new instance of Pool.
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/litestack/litesupport.rb', line 83 def initialize(count, &block) @count = count @block = block @resources = Thread::Queue.new @mutex = Litesupport::Mutex.new @count.times do resource = @mutex.synchronize { block.call } @resources << resource end end |
Instance Method Details
#acquire ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/litestack/litesupport.rb', line 94 def acquire result = nil resource = @resources.pop begin result = yield resource ensure @resources << resource end result end |