Build Status Coverage Status

SilentWorker

SilentWorker gives simple worker thread model.

Installation

Add this line to your application's Gemfile:

gem 'silent_worker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install silent_worker

Usage

sw = SilentWorker.new(2) do |data|
  puts data
  sleep 0.01
end

10.times |n|
  sw << n
end

sw.wait

# => 
#  1
#  0
#  2
#  3
#  4
#  5
#  6
#  7
#  8
#  9

# NOTE: Order is a random

Real world example:

parallel = 8

sw = SilentWorker.new(parallel) do |url|
  system("wget", url)
end

File.open('url_list.txt').each_line do |line|
  sw << line.strip
end

File.open('url_list2.txt').each_line do |line|
  sw << line.strip
end

sw.wait

This example will be 8 paralleled wget from url_list.txt and url_list2.txt such as cat url_list.txt url_list2.txt | xargs -P8 -n1 wget.

See Also

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