class MailHandler::ThreadedWorker

Generic threaded worker

Constants

WORKER_SIZE

Public Class Methods

new(task_list) click to toggle source
# File lib/workers/threaded_worker.rb, line 6
def initialize(task_list)
  @tasks = Queue.new
  populate_que task_list
end

Public Instance Methods

do_work() { |task| ... } click to toggle source
# File lib/workers/threaded_worker.rb, line 11
def do_work
  WORKER_SIZE.times do
    Thread.new do
      while (task = @tasks.pop)
        yield task
      end
    end
  end
end
done?() click to toggle source
# File lib/workers/threaded_worker.rb, line 21
def done?
  @tasks.size.zero?
end

Private Instance Methods

populate_que(task_list) click to toggle source
# File lib/workers/threaded_worker.rb, line 27
def populate_que(task_list)
  task_list.each { |task| @tasks << task }
end