Class: Pallets::Pool
- Inherits:
-
Object
- Object
- Pallets::Pool
- Defined in:
- lib/pallets/pool.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(size) ⇒ Pool
constructor
A new instance of Pool.
- #size ⇒ Object
Constructor Details
#initialize(size) ⇒ Pool
Returns a new instance of Pool.
3 4 5 6 7 8 9 |
# File 'lib/pallets/pool.rb', line 3 def initialize(size) raise ArgumentError, 'Pool needs a block to initialize' unless block_given? @queue = Queue.new @size = size size.times { @queue << yield } end |
Instance Method Details
#execute ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pallets/pool.rb', line 15 def execute raise ArgumentError, 'Pool needs a block to execute' unless block_given? begin item = @queue.pop yield item ensure @queue << item end end |
#size ⇒ Object
11 12 13 |
# File 'lib/pallets/pool.rb', line 11 def size @queue.size end |