class BooticCli::WorkerPool

Public Class Methods

new(how_many) click to toggle source
# File lib/bootic_cli/worker_pool.rb, line 4
def initialize(how_many)
  @how_many = how_many
  @queue = Queue.new
end

Public Instance Methods

schedule(&block) click to toggle source
# File lib/bootic_cli/worker_pool.rb, line 9
def schedule(&block)
  @queue.push block
end
start() click to toggle source
# File lib/bootic_cli/worker_pool.rb, line 13
def start
  threads = @how_many.times.map do |i|
    Thread.new do
      begin
        while job = @queue.pop(true)
          job.call
        end
      rescue ThreadError
      end
    end
  end
  threads.map(&:join)
end