Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A Ruby threadpool library to handle threadpools and make batch jobs easier
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


Threadz Thread Pool Library

Status Dependency Status


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 =
T1.process { puts "my first task" }
T1.process { puts "my second task" }

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

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


# You can do other things, too

T3 =
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 }
puts b.errors

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

# 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).


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.