Module: Listen::Internals::ThreadPool

Defined in:
lib/listen/internals/thread_pool.rb

Class Method Summary collapse

Class Method Details

.add(&block) ⇒ Object



5
6
7
8
9
# File 'lib/listen/internals/thread_pool.rb', line 5

def self.add(&block)
  Thread.new { block.call }.tap do |th|
    (@threads ||= Queue.new) << th
  end
end

.stopObject



11
12
13
14
15
16
17
18
# File 'lib/listen/internals/thread_pool.rb', line 11

def self.stop
  return unless @threads ||= nil
  return if @threads.empty? # return to avoid using possibly stubbed Queue

  killed = Queue.new
  killed << @threads.pop.kill until @threads.empty?
  killed.pop.join until killed.empty?
end