Class: Async::Container::Hybrid

Inherits:
Forked show all
Defined in:
lib/async/container/hybrid.rb

Constant Summary

Constants inherited from Generic

Generic::UNNAMED

Instance Attribute Summary

Attributes inherited from Generic

#state, #statistics

Instance Method Summary collapse

Methods inherited from Forked

multiprocess?, #start

Methods inherited from Generic

#[], #async, #failed?, #initialize, #key?, #mark?, #reload, run, #running?, #sleep, #spawn, #status?, #stop, #to_s, #wait, #wait_until_ready

Constructor Details

This class inherits a constructor from Async::Container::Generic

Instance Method Details

#run(count: nil, forks: nil, threads: nil, **options, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/async/container/hybrid.rb', line 29

def run(count: nil, forks: nil, threads: nil, **options, &block)
	processor_count = Container.processor_count
	count ||= processor_count ** 2
	forks ||= [processor_count, count].min
	threads = (count / forks).ceil
	
	forks.times do
		self.spawn(**options) do
			container = Threaded::Container.new
			
			container.run(count: threads, **options, &block)
			
			container.wait
		end
	end
	
	return self
end