module GemsBond::Helpers::ConcurrencyHelper

Concurrency helper

Public Instance Methods

each_concurrently(items) { |item| ... } click to toggle source

Run each item concurrently @param items [Boolean] items to process @yield [item] apply to each item @return [void] @example

each_concurrently(words) do |word|
  dictionnary_api.fetch(word)
end
# File lib/gems_bond/helpers/concurrency_helper.rb, line 15
def each_concurrently(items)
  threads = []
  items.each do |item|
    threads << Thread.new { block_given? ? yield(item) : item }
  end
  threads.each(&:join)
end