Class: Pool
- Inherits:
-
Object
- Object
- Pool
- Defined in:
- lib/genevalidator/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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/genevalidator/pool.rb', line 27 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
43 44 45 |
# File 'lib/genevalidator/pool.rb', line 43 def schedule(*args, &block) @jobs << [block, args] end |
#shutdown ⇒ Object
47 48 49 50 51 52 |
# File 'lib/genevalidator/pool.rb', line 47 def shutdown @size.times do schedule { throw :exit } end @pool.map(&:join) end |