Module: Enumerable
- Defined in:
- lib/mb/core_ext/enumerable.rb
Instance Method Summary collapse
-
#concurrent_map(method_name = nil, *args, &block) ⇒ Array
(also: #concurrent_collect)
Map across all members using Celluloid futures, and wait for the results.
Instance Method Details
#concurrent_map(method_name = nil, *args, &block) ⇒ Array Also known as: concurrent_collect
Map across all members using Celluloid futures, and wait for the results.
This chooses the best behavior based on each item, and whether a method and argument list or block are passed.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mb/core_ext/enumerable.rb', line 28 def concurrent_map(method_name = nil, *args, &block) futures = if method_name map { |item| if item.respond_to?(:future) item.future(method_name, *args) else Celluloid::Future.new { item.send(method_name, *args) } end } elsif block_given? map { |item| Celluloid::Future.new { block.yield item } } else raise ArgumentError, "Requires method and argument list, or a block" end futures.map(&:value) end |