Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby threadpool library to handle threadpools and make batch jobs easier

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 threadz.gemspec

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.