class RsyncCommand::ThreadPool
Attributes
default_size[RW]
Public Class Methods
new(size=nil)
click to toggle source
# File vendor/rsync_command/lib/rsync_command/thread_pool.rb, line 9 def initialize(size=nil) @size = size || ThreadPool.default_size || 10 @jobs = Queue.new @retvals = [] @pool = Array.new(@size) do |i| Thread.new do Thread.current[:id] = i catch(:exit) do loop do job, args = @jobs.pop @retvals << job.call(*args) end end end end end
Public Instance Methods
schedule(*args, &block)
click to toggle source
# File vendor/rsync_command/lib/rsync_command/thread_pool.rb, line 25 def schedule(*args, &block) @jobs << [block, args] end
shutdown()
click to toggle source
# File vendor/rsync_command/lib/rsync_command/thread_pool.rb, line 28 def shutdown @size.times do schedule { throw :exit } end @pool.map(&:join) @retvals end