Class: ThreadPool

Inherits:
Object
  • Object
show all
Defined in:
lib/thread_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tasks, thread_limit, thread_object = Thread) ⇒ ThreadPool

Returns a new instance of ThreadPool.



4
5
6
7
8
# File 'lib/thread_pool.rb', line 4

def initialize(tasks, thread_limit, thread_object=Thread)
  @queue         = populate_queue(tasks)
  @thread_limit  = thread_limit
  @thread_object = thread_object
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



2
3
4
# File 'lib/thread_pool.rb', line 2

def queue
  @queue
end

Instance Method Details

#executeObject



10
11
12
13
14
# File 'lib/thread_pool.rb', line 10

def execute
  (0...@thread_limit).map do
    create_worker
  end.each(&:join)
end