class InThreads::Pool
Thread pool
Attributes
exception[R]
Public Class Methods
new(thread_count)
click to toggle source
# File lib/in_threads.rb, line 180 def initialize(thread_count) @queue = Queue.new @mutex = Mutex.new @pool = Array.new(thread_count) do Thread.new do while (block = @queue.pop) block.call break if stop? end end end end
Public Instance Methods
catch() { || ... }
click to toggle source
# File lib/in_threads.rb, line 211 def catch yield rescue Exception => e @mutex.synchronize{ @exception ||= e } unless @exception nil end
finalize()
click to toggle source
# File lib/in_threads.rb, line 205 def finalize @pool. each{ @queue.push(nil) }. each(&:join) end
run(&block)
click to toggle source
# File lib/in_threads.rb, line 193 def run(&block) @queue.push(block) end
stop!()
click to toggle source
# File lib/in_threads.rb, line 201 def stop! @stop = true end
stop?()
click to toggle source
# File lib/in_threads.rb, line 197 def stop? @stop || @exception end