module Driskell::Listen::Internals::ThreadPool

Public Class Methods

add(&block) click to toggle source
# File lib/driskell-listen/internals/thread_pool.rb, line 5
def self.add(&block)
  Thread.new { block.call }.tap do |th|
    (@threads ||= Queue.new) << th
  end
end
stop() click to toggle source
# File lib/driskell-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