Class: Bob::BackgroundEngines::Threaded::ThreadPool
- Defined in:
- lib/bob/background_engines/threaded.rb
Defined Under Namespace
Classes: Incrementor
Instance Attribute Summary collapse
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #add(*jobs, &blk) ⇒ Object (also: #push, #<<)
-
#initialize(size = nil) ⇒ ThreadPool
constructor
A new instance of ThreadPool.
- #njobs ⇒ Object
Constructor Details
#initialize(size = nil) ⇒ ThreadPool
Returns a new instance of ThreadPool.
69 70 71 72 73 74 |
# File 'lib/bob/background_engines/threaded.rb', line 69 def initialize(size = nil) size ||= 2 @jobs = Queue.new @njobs = Incrementor.new @workers = Array.new(size) { spawn } end |
Instance Attribute Details
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
53 54 55 |
# File 'lib/bob/background_engines/threaded.rb', line 53 def jobs @jobs end |
#size ⇒ Object
Returns the value of attribute size.
53 54 55 |
# File 'lib/bob/background_engines/threaded.rb', line 53 def size @size end |
Instance Method Details
#add(*jobs, &blk) ⇒ Object Also known as: push, <<
76 77 78 79 80 81 82 83 |
# File 'lib/bob/background_engines/threaded.rb', line 76 def add(*jobs, &blk) jobs = jobs + Array(blk) jobs.each do |job| @jobs << job @njobs.inc end end |
#njobs ⇒ Object
88 89 90 |
# File 'lib/bob/background_engines/threaded.rb', line 88 def njobs @njobs.to_i end |