class Enparallel::ThreadPool

Attributes

worker_count[RW]

Public Class Methods

new(tasks, requested_worker_count, rule) click to toggle source
# File lib/enparallel/thread_pool.rb, line 5
def initialize(tasks, requested_worker_count, rule)
    @tasks = tasks
    @worker_count = [tasks.length, requested_worker_count].min
    @picker = Picker.new(tasks, rule.to_sym)
end

Public Instance Methods

drain() click to toggle source
# File lib/enparallel/thread_pool.rb, line 16
def drain
    @workers = @worker_count.times.map do
        Thread.new do
            while task = @picker.next
                task.run
            end
        end
    end
end
drain_wait() click to toggle source
# File lib/enparallel/thread_pool.rb, line 11
def drain_wait
    drain
    join
end
failed_tasks() click to toggle source
# File lib/enparallel/thread_pool.rb, line 38
def failed_tasks
    @tasks.reject(&:has_succeeded?)
end
get_log_groups() click to toggle source
# File lib/enparallel/thread_pool.rb, line 50
def get_log_groups
    logger.get_log_groups
end
logger() click to toggle source
# File lib/enparallel/thread_pool.rb, line 54
def logger
    @logger ||= Logger.from_thread_pool(self)
end
render() click to toggle source
# File lib/enparallel/thread_pool.rb, line 30
def render
    @tasks.map(&:char).join.bold
end
size() click to toggle source
# File lib/enparallel/thread_pool.rb, line 26
def size
    @tasks.length
end
succeeded_tasks() click to toggle source
# File lib/enparallel/thread_pool.rb, line 34
def succeeded_tasks
    @tasks.select(&:has_succeeded?)
end
tasks_of(type) click to toggle source
# File lib/enparallel/thread_pool.rb, line 42
def tasks_of(type)
    if type == :success
        succeeded_tasks
    elsif type == :failure
        failed_tasks
    end
end

Private Instance Methods

join() click to toggle source
# File lib/enparallel/thread_pool.rb, line 60
def join
    @workers.each(&:join)
end