lib/tpool.rb in tpool-0.0.1 vs lib/tpool.rb in tpool-0.0.2

- old
+ new

@@ -1,8 +1,12 @@ require "thread" class Tpool + attr_reader :args + + ARGS_VALID = [:threads, :priority, :on_error] + def self.const_missing(name) require "#{File.dirname(__FILE__)}/tpool_#{name.to_s.downcase}.rb" raise "Still not defined: '#{name}'." if !Tpool.const_defined?(name) return Tpool.const_get(name) end @@ -13,14 +17,19 @@ raise "No block was found running in that thread." end def initialize(args) @args = args + @args.each do |key, val| + raise "Invalid argument given: '#{key}'." if Tpool::ARGS_VALID.index(key) == nil + end + @queue = Queue.new self.start end + #Starts the thread-pool. This is automatically called on initialization. def start raise "Already started." if @pool and !@pool.empty? @pool = Array.new(@args[:threads]) do |i| Thread.new do @@ -55,9 +64,10 @@ raise "No block was given." if !blk block = Tpool::Block.new( :args => args, :blk => blk, + :tpool => self, :thread_starts => [Thread.current] ) @queue << block begin \ No newline at end of file