Class: Outlander::ThreadsPool
- Inherits:
-
Object
- Object
- Outlander::ThreadsPool
- Defined in:
- lib/outlander/threads_pool.rb
Instance Method Summary collapse
- #enqueue(&task) ⇒ Object
-
#initialize(num_threads = 3) ⇒ ThreadsPool
constructor
A new instance of ThreadsPool.
- #start ⇒ Object
Constructor Details
#initialize(num_threads = 3) ⇒ ThreadsPool
Returns a new instance of ThreadsPool.
7 8 9 10 |
# File 'lib/outlander/threads_pool.rb', line 7 def initialize(num_threads = 3) @num_threads = num_threads @queue = Queue.new end |
Instance Method Details
#enqueue(&task) ⇒ Object
12 13 14 |
# File 'lib/outlander/threads_pool.rb', line 12 def enqueue(&task) @queue << task end |
#start ⇒ Object
16 17 18 19 20 |
# File 'lib/outlander/threads_pool.rb', line 16 def start raise "Could not start with empty queue" if @queue.empty? run_threads @num_threads sleep 1 until @queue.empty? && @queue.num_waiting == @num_threads end |