Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A Ruby threadpool library to handle threadpools and make batch jobs easier
Ruby
branch: master

Cleaning up rdoc, incorporating some feedback, renaming some variable…

…s to be more meaningful. Added some locks where I thought they were needed.
latest commit 5d96e05256
@nanodeath authored
Failed to load latest commit information.
lib Cleaning up rdoc, incorporating some feedback, renaming some variable…
spec Cleaning up rdoc, incorporating some feedback, renaming some variable…
.gitignore Updating .gitignore.
.travis.yml Add rdoc gem and java as platforms, remove 1.8.x build targets from .…
CHANGELOG Adding support for proper exception handling.
Gemfile Add rdoc gem and java as platforms, remove 1.8.x build targets from .…
Gemfile.lock Cleaning up rdoc, incorporating some feedback, renaming some variable…
MIT-LICENSE Added some administrative stuff
README.rdoc Cleaning up rdoc, incorporating some feedback, renaming some variable…
Rakefile
threadz.gemspec Upgrading rspec to 2.x.

README.rdoc

Threadz Thread Pool Library

Build
Status Dependency Status

Description

This is a thread pool library that you can do two main things with, which I'll demonstrate in code:

# These are more for "fire and forget" tasks
T1 = Threadz::ThreadPool.new
T1.process { puts "my first task" }
T1.process { puts "my second task" }

# If you care when the tasks complete, use batches
T2 = Threadz::ThreadPool.new
b = T2.new_batch
b << lambda { puts "my first task" }
b << lambda { puts "my second task" }

puts "do a couple of other things..."

b.wait_until_done

# You can do other things, too

T3 = Threadz::ThreadPool.new
b = T3.new_batch
b << lambda { puts "my first task" }
b << lambda { puts "my second task" }

puts "do a couple of other things..."

b.when_done { puts "woohoo, done with tasks" }

puts "and some other stuff, blah"

b = T3.new_batch
b << lambda { 10000000.times {} }

b.wait_until_done(:timeout => 0.1)
puts b.completed? ? "finished!" : "didn't finish"

# Error handling
b = T3.new_batch(:max_retries => 3)
b << lambda { raise }
b.wait_until_done
puts b.errors

b = T3.new_batch(:max_retries => 3, :error_handler => lambda { |error, control| puts "Error! #{error}" })
b << lambda { raise }
b.wait_until_done

# See the specs for more error handling stuff.  Much better examples.

The thread pool is also smart – depending on load, it can either spawn or cull additional threads (at a rate you can set).

Examples

For examples, please see the well-documented specs. They're all fairly simple and straightforward. Please message me if you have issues that aren't answered by reading the spec.

Something went wrong with that request. Please try again.