Class: Future::Threadpool
- Inherits:
-
Object
- Object
- Future::Threadpool
- Defined in:
- lib/futurevalue/threadpool.rb
Instance Method Summary collapse
- #<<(job) ⇒ Object
- #close ⇒ Object
-
#initialize(count) ⇒ Threadpool
constructor
A new instance of Threadpool.
- #workers ⇒ Object
- #workers=(value) ⇒ Object
Constructor Details
#initialize(count) ⇒ Threadpool
Returns a new instance of Threadpool.
5 6 7 8 9 |
# File 'lib/futurevalue/threadpool.rb', line 5 def initialize(count) @queue = Queue.new @workers = [] self.workers = count end |
Instance Method Details
#<<(job) ⇒ Object
23 24 25 |
# File 'lib/futurevalue/threadpool.rb', line 23 def << (job) @queue << job end |
#close ⇒ Object
27 28 29 30 |
# File 'lib/futurevalue/threadpool.rb', line 27 def close self.workers = 0 @workers.each(&:join) end |
#workers ⇒ Object
11 12 13 |
# File 'lib/futurevalue/threadpool.rb', line 11 def workers @workers.size end |
#workers=(value) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/futurevalue/threadpool.rb', line 15 def workers=(value) if value > workers (value-workers).times { @workers << new_worker } else (workers-value).times { @queue << proc { @workers.delete(Thread.current); Thread.current.exit } } end end |