Module: SassListen::Internals::ThreadPool

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

Class Method Summary collapse

Class Method Details

.add(&block) ⇒ Object



5
6
7
8
9
# File 'lib/sass-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
19
20
21
22
23
24
25
26
# File 'lib/sass-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
  # You can't kill a read on a descriptor in JRuby, so let's just
  # ignore running threads (listen rb-inotify waiting for disk activity
  # before closing)  pray threads die faster than they are created...
  limit = RUBY_ENGINE == 'jruby' ? [1] : []

  killed << @threads.pop.kill until @threads.empty?
  until killed.empty?
    th = killed.pop
    th.join(*limit) unless th[:listen_blocking_read_thread]
  end
end