Sha256: 32bd40168c8812babdc0bbe64004c154f76d95e367ef32a2fb1a3f9a0bf1d8a3

Contents?: true

Size: 727 Bytes

Versions: 12

Compression:

Stored size: 727 Bytes

Contents

require 'thread'

class RsyncCommand
  class ThreadPool
    class << self
      attr_accessor :default_size
    end

    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
    def schedule(*args, &block)
      @jobs << [block, args]
    end
    def shutdown
      @size.times do
        schedule { throw :exit }
      end
      @pool.map(&:join)
      @retvals
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
leap_cli-1.9.2 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.9.1 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.9 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.8.1 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.8 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.7.4 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.7.3 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.6.2 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.5.6 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.5.1 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.5.0 vendor/rsync_command/lib/rsync_command/thread_pool.rb
leap_cli-1.2.5 vendor/rsync_command/lib/rsync_command/thread_pool.rb