Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ruby Thread Pool

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
Octocat-spinner-32 thread_pool.gemspec
README
This is a fork of http://github.com/fizx/thread_pool
_____________________
This code is still pretty early, and not yet used in production.  That said, I am interested in feedback.  You can send me a message on GitHub's internal messaging system ( http://github.com/inbox/new/fizx ).

A simple executor-style ThreadPool for Ruby (with tests, yay!)

Usage:

	require "rubygems"
	require "thread_pool"
	pool = ThreadPool.new(threads = 10)
	pool.execute { puts "I'm writing from a thread" }
	pool.join
	
It's often useful to make sure that the properties of Ruby's blocks don't bite you.  The following code will usually print three nils, because n keeps changing.

	pool = ThreadPool.new(threads = 10)
	numbers = [1, 2, 3]
	while n = numbers.shift
		pool.execute { puts n.inspect }
	end
	pool.join
	
Passing arguments to execute avoids this. i.e.:

	pool = ThreadPool.new(threads = 10)
	numbers = [1, 2, 3]
	while n = numbers.shift
		pool.execute(n) {|local| puts local.inspect }
	end
	pool.join
Something went wrong with that request. Please try again.