MultithreadsEach

Simple syntactic sugar for arrays that performs the same actions as the method each, but creates a new thread for every call

Installation

Add this line to your application's Gemfile:

gem 'multithreads_each'

Or install it yourself as:

$ gem install multithreads_each

Usage

Using almost the same as the method each:

cities = %w(Moscow Berlin London Praga Kiev)

cities.multithreads_each do |city|
  # Actions
end

For each element will be created a new thread:

def slow_function(foo)
  sleep 5
  puts foo
end

array = %w(1 2 3 4 5)

# Will be completed after ~25 seconds
array.each do |elem|
  slow_function(elem)
end

# Will be completed after ~5 seconds
array.multithreads_each do |elem|
  slow_function(elem)
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request