module Tresse

Constants

VERSION

Public Class Methods

call_block(block, args) click to toggle source
# File lib/tresse.rb, line 72
def self.call_block(block, args)

  block.call(*args[0, block.arity.abs])
end
enqueue(batch) click to toggle source
# File lib/tresse.rb, line 17
def enqueue(batch)

  @work_queue << batch

  batch.group
end
init() click to toggle source
# File lib/tresse.rb, line 11
def init

  @work_queue = Queue.new
  @work_threads = 8.times.collect { |i| make_work_thread }
end
max_work_thread_count() click to toggle source
# File lib/tresse.rb, line 24
def max_work_thread_count

  @work_threads.size
end
max_work_thread_count=(i) click to toggle source
# File lib/tresse.rb, line 29
def max_work_thread_count=(i)

  i0 = @work_threads.size

  @work_threads << make_work_thread while @work_threads.size < i
  @work_threads.pop while @work_threads.size > i

  i
end

Protected Class Methods

make_work_thread() click to toggle source
# File lib/tresse.rb, line 41
def make_work_thread

  Thread.new do

    t = Thread.current
    t[:tresse] = true

    loop do
      begin

        batch = @work_queue.pop

        unless @work_threads.include?(t)
          @work_queue << batch
          break
        end

        batch.process

      rescue => err

        batch.error = err
      end
    end
  end
end