0.0
No commit activity in last 3 years
No release in over 3 years
Hyper Thread is simple, flexible thread pool library for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0

Runtime

>= 0
 Project Readme

Hyper Thread Header

Hyper Thread

Hyper Thread is simple, flexible thread pool library for Ruby.

Installation

$ gem install hyper_thread

Usage

require 'hyper_thread'

# make a pool of maximum 7 threads
pool = HyperThread.pool.new(max: 7)

# spawn 7 threads, and 3 jobs will be added to the queue
pool.async(count: 10) do
  puts "some work to do"
end

# spool off queued jobs outside of thread pool
pool.todo(count: pool.queue.size) do |block|
  block.call # "some work to do"
end

# kill off any dead threads
pool.reap

# queue up 300 jobs
counter = 0

pool.qsync(count: 300) do
  puts "some work to do #{counter += 1}"
end

# spawn 2 threads to manage the queue forever
pool.async(forever: true, count: 2) do
  pool.todo do |block|
    block.call
  end
end

# let them manage that queue for roughly 2 seconds
sleep 2

# shutdown the thread pool
pool.shutdown

License

The gem is available as open source under the terms of the MIT License.