Class: ThreadPool
- Inherits:
-
Object
- Object
- ThreadPool
- Defined in:
- lib/tpkg/thread_pool.rb
Defined Under Namespace
Classes: Worker
Instance Attribute Summary collapse
-
#max_size ⇒ Object
Returns the value of attribute max_size.
Instance Method Summary collapse
- #busy? ⇒ Boolean
-
#initialize(max_size = 10) ⇒ ThreadPool
constructor
A new instance of ThreadPool.
- #process(block = nil, &blk) ⇒ Object
- #shutdown ⇒ Object (also: #join)
- #size ⇒ Object
Constructor Details
#initialize(max_size = 10) ⇒ ThreadPool
Returns a new instance of ThreadPool.
80 81 82 83 84 |
# File 'lib/tpkg/thread_pool.rb', line 80 def initialize(max_size = 10) @max_size = max_size @queue = Queue.new @workers = [] end |
Instance Attribute Details
#max_size ⇒ Object
Returns the value of attribute max_size.
78 79 80 |
# File 'lib/tpkg/thread_pool.rb', line 78 def max_size @max_size end |
Instance Method Details
#busy? ⇒ Boolean
90 91 92 |
# File 'lib/tpkg/thread_pool.rb', line 90 def busy? @queue.size < @workers.size end |
#process(block = nil, &blk) ⇒ Object
101 102 103 104 105 |
# File 'lib/tpkg/thread_pool.rb', line 101 def process(block=nil,&blk) block = blk if block_given? worker = get_worker worker.set_block(block) end |
#shutdown ⇒ Object Also known as: join
94 95 96 97 |
# File 'lib/tpkg/thread_pool.rb', line 94 def shutdown @workers.each { |w| w.stop } @workers = [] end |
#size ⇒ Object
86 87 88 |
# File 'lib/tpkg/thread_pool.rb', line 86 def size @workers.size end |