SimpleWorker
Simple Worker Library
Installation
Add this line to your application's Gemfile:
gem 'simple-worker'
And then execute:
$ bundle
Or install it yourself as:
$ gem install simple-worker
Usage
worker = SimpleWorker::Worker.new
worker.push {puts 'world'}
puts 'hello'
# output:
# hello
# world
worker = SimpleWorker::Worker.new
worker.push Proc.new {puts 'world'}
puts 'hello'
# output:
# hello
# world
worker = SimpleWorker::Worker.new(2)
5.times do |i|
worker.push do |thread_id|
sleep 1
puts "thread_id=#{thread_id} value=#{i}"
end
end
sleep 5
# output:
# thread_id=0 value=1
# thread_id=1 value=0
# thread_id=0 value=2
# thread_id=1 value=3
# thread_id=0 value=4
Contributing
- Fork it ( https://github.com/kurochan/simple-worker/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request