Method: BBK::App::ThreadPool#initialize
- Defined in:
- lib/bbk/app/thread_pool.rb
#initialize(size, queue: 10) ⇒ ThreadPool
Returns a new instance of ThreadPool.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bbk/app/thread_pool.rb', line 9 def initialize(size, queue: 10) @jobs = SizedQueue.new(queue) @shutdown = false @term = false @threads = size.times.map do Thread.new(@jobs) do |jobs| begin Thread.current.report_on_exception = true Thread.current.abort_on_exception = true unless @shutdown until @term job, args = jobs.pop break if @term || job == :exit job.call(*args) end end rescue StandardError => e warn "[CRITICAL]: ThreadPool exception: #{e}" warn "[CRITICAL]: #{e.backtrace.join("\n")}" # Thread.main.raise e exit(1) end end end end |