class Concurrent::RubyThreadPoolWorker
@!visibility private
def dead?
def dead? return @mutex.synchronize do @thread.nil? ? false : ! @thread.alive? end end
def initialize(queue, parent)
def initialize(queue, parent) @queue = queue @parent = parent @mutex = Mutex.new @last_activity = Time.now.to_f end
def kill
def kill @mutex.synchronize do Thread.kill(@thread) unless @thread.nil? @thread = nil end end
def last_activity
def last_activity @mutex.synchronize { @last_activity } end
def run(thread = Thread.current)
def run(thread = Thread.current) @mutex.synchronize do raise StandardError.new('already running') unless @thread.nil? @thread = thread end loop do task = @queue.pop if task == :stop @thread = nil @parent.on_worker_exit(self) break end begin task.last.call(*task.first) rescue => ex # let it fail ensure @last_activity = Time.now.to_f @parent.on_end_task end end end
def status
def status @mutex.synchronize do return 'not running' if @thread.nil? @thread.status end end