Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fizx-thread_pool

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fizx-thread_pool

  • 0.3.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 11 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc