class Concurrent::RubyThreadPoolExecutor::Worker

@!visibility private

Public Class Methods

new(pool, id) click to toggle source
# File lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb, line 306
def initialize(pool, id)
  # instance variables accessed only under pool's lock so no need to sync here again
  @queue  = Queue.new
  @pool   = pool
  @thread = create_worker @queue, pool, pool.idletime

  if @thread.respond_to?(:name=)
    @thread.name = [pool.name, 'worker', id].compact.join('-')
  end
end

Public Instance Methods

<<(message) click to toggle source
# File lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb, line 317
def <<(message)
  @queue << message
end
kill() click to toggle source
# File lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb, line 325
def kill
  @thread.kill
end
stop() click to toggle source
# File lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb, line 321
def stop
  @queue << :stop
end

Private Instance Methods

create_worker(queue, pool, idletime) click to toggle source
# File lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb, line 331
def create_worker(queue, pool, idletime)
  Thread.new(queue, pool, idletime) do |my_queue, my_pool, my_idletime|
    catch(:stop) do
      loop do

        case message = my_queue.pop
        when :stop
          my_pool.remove_busy_worker(self)
          throw :stop

        else
          task, args = message
          run_task my_pool, task, args
          my_pool.ready_worker(self, Concurrent.monotonic_time)
        end
      end
    end
  end
end
run_task(pool, task, args) click to toggle source
# File lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb, line 351
def run_task(pool, task, args)
  task.call(*args)
  pool.worker_task_completed
rescue => ex
  # let it fail
  log DEBUG, ex
rescue Exception => ex
  log ERROR, ex
  pool.worker_died(self)
  throw :stop
end