Class: Pool
- Inherits:
-
Object
- Object
- Pool
- Defined in:
- lib/itriagetestrail/pool.rb
Instance Method Summary collapse
-
#initialize(size) ⇒ Pool
constructor
A new instance of Pool.
- #schedule(*args, &block) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(size) ⇒ Pool
Returns a new instance of Pool.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/itriagetestrail/pool.rb', line 4 def initialize(size) @size = size @jobs = Queue.new @pool = Array.new(@size) do |i| Thread.new do Thread.current[:id] = i catch(:exit) do loop do job, args = @jobs.pop job.call(*args) end end end end end |
Instance Method Details
#schedule(*args, &block) ⇒ Object
22 23 24 |
# File 'lib/itriagetestrail/pool.rb', line 22 def schedule(*args, &block) @jobs << [block, args] end |
#shutdown ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/itriagetestrail/pool.rb', line 26 def shutdown @size.times do schedule { throw :exit } end @pool.map(&:join) end |