Module: GemsBond::Helpers::ConcurrencyHelper

Included in:
Gem, Spy::All
Defined in:
lib/gems_bond/helpers/concurrency_helper.rb

Overview

Concurrency helper

Instance Method Summary collapse

Instance Method Details

#each_concurrently(items) {|item| ... } ⇒ void

This method returns an undefined value.

Run each item concurrently

Examples:

each_concurrently(words) do |word|
  dictionnary_api.fetch(word)
end

Parameters:

  • items (Boolean)

    items to process

Yields:

  • (item)

    apply to each item



15
16
17
18
19
20
21
# 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