| 
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 | # File 'lib/common/thread_pool.rb', line 60
def create_thread
  thread = Thread.new do
    begin
      loop do
        action = nil
        @lock.synchronize do
          action = @actions.shift unless @boom
          unless action
            @logger.debug('Thread is no longer needed, cleaning up')
            @available_threads += 1
            @threads.delete(thread) if @state == :open
          end
        end
        break unless action
        begin
          action.call
        rescue Exception => e
          raise_worker_exception(e)
        end
      end
    end
    @lock.synchronize { @cv.signal unless working? }
  end
  @threads << thread
end |