Method: ThreadStorm#initialize
- Defined in:
- lib/thread_storm.rb
#initialize(options = {}) ⇒ ThreadStorm
call-seq:
new(options = {}) -> thread_storm
new(options = {}){ |self| ... } -> thread_storm
Valid options are…
:size => How many threads to spawn.
:timeout => Max time an execution is allowed to run before terminating it. Nil means no timeout.
:timeout_method => An object that implements something like Timeout.timeout via #call..
:default_value => Value of an execution if it times out or errors..
:reraise => True if you want exceptions to be reraised when ThreadStorm#join is called.
:execute_blocks => True if you want #execute to block until there is an available thread.
For defaults, see DEFAULTS.
When given a block, ThreadStorm#join and ThreadStorm#shutdown are called for you. In other words…
ThreadStorm.new do |storm|
storm.execute{ sleep(1) }
end
…is the same as…
storm = ThreadStorm.new
storm.execute{ sleep(1) }
storm.join
storm.shutdown
60 61 62 63 64 65 66 |
# File 'lib/thread_storm.rb', line 60 def initialize( = {}) @options = .reverse_merge(self.class.) @queue = Queue.new(@options[:size], @options[:execute_blocks]) @executions = [] @workers = (1..@options[:size]).collect{ Worker.new(@queue) } run{ yield(self) } if block_given? end |