Class: Evilution::Parallel::Pool
- Inherits:
-
Object
- Object
- Evilution::Parallel::Pool
- Defined in:
- lib/evilution/parallel/pool.rb
Instance Method Summary collapse
-
#initialize(size:) ⇒ Pool
constructor
A new instance of Pool.
- #map(items, &block) ⇒ Object
Constructor Details
#initialize(size:) ⇒ Pool
Returns a new instance of Pool.
6 7 8 9 10 |
# File 'lib/evilution/parallel/pool.rb', line 6 def initialize(size:) raise ArgumentError, "pool size must be a positive integer, got #{size.inspect}" unless size.is_a?(Integer) && size >= 1 @size = size end |
Instance Method Details
#map(items, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/evilution/parallel/pool.rb', line 12 def map(items, &block) results = [] items.each_slice(@size) do |batch| results.concat(run_batch(batch, &block)) end results end |