Git Product home page Git Product logo

thread_pool's Introduction

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

thread_pool's People

Contributors

fizx avatar

Stargazers

ypcpy avatar  avatar  avatar Angus H. avatar  avatar Nuno Santos avatar Andrey Snow avatar Andrew Cholakian avatar Heikki Rauhala avatar eLafo avatar Dan Chen avatar Cory Osborn avatar Salomão Junior avatar Paul Leitmanis avatar Max Justus Spransy avatar Sidu Ponnappa avatar Robert Lee avatar Ilya Grigorik avatar Joshua Hull avatar Kenneth Kalmer avatar Jeremy Stephens avatar  avatar Darragh Curran avatar  avatar Scott Taylor avatar K. Adam Christensen avatar Aaron Suggs avatar Simon Menke avatar Lourens Naudé avatar

Watchers

James Cloos avatar Andrey Bronin avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.