lib/bundler/worker.rb in bundler-1.11.2 vs lib/bundler/worker.rb in bundler-1.12.0.pre.1

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true require "thread" module Bundler class Worker POISON = Object.new @@ -9,18 +10,27 @@ def initialize(exn) @exception = exn end end + # @return [String] the name of the worker + attr_reader :name + # Creates a worker pool of specified size # # @param size [Integer] Size of pool + # @param name [String] name the name of the worker # @param func [Proc] job to run in inside the worker pool - def initialize(size, func) + def initialize(size, name, func) + @name = name @request_queue = Queue.new @response_queue = Queue.new @func = func - @threads = size.times.map {|i| Thread.start { process_queue(i) } } + @threads = Array.new(size) do |i| + Thread.start { process_queue(i) }.tap do |thread| + thread.name = "#{name} Worker ##{i}" if thread.respond_to?(:name=) + end + end trap("INT") { abort_threads } end # Enqueue a request to be executed in the worker pool #