Module: Listen::Internals::ThreadPool

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

Overview

Just a wrapper for tests to avoid interfereing with Celluloid’s threads

Class Method Summary collapse

Class Method Details

.add(&block) ⇒ Object



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

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

.stopObject



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

def self.stop
  return unless @threads ||= nil

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