Class: Async::Container::Forked

Inherits:
Object
  • Object
show all
Defined in:
lib/async/container/forked.rb

Defined Under Namespace

Classes: Instance

Instance Method Summary collapse

Constructor Details

#initialize(concurrency: 1, name: nil, &block) ⇒ Forked

Returns a new instance of Forked.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/async/container/forked.rb', line 38

def initialize(concurrency: 1, name: nil, &block)
	@pids = concurrency.times.collect do
		fork do
			Process.setproctitle(name) if name
			
			begin
				Async::Reactor.run(Instance.new, &block)
			rescue Interrupt
				# Exit cleanly.
			end
		end
	end
	
	@finished = false
end

Instance Method Details

#stop(signal = :TERM) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/async/container/forked.rb', line 64

def stop(signal = :TERM)
	@pids.each do |pid|
		::Process.kill(signal, pid) rescue nil
	end
	
	wait
end

#waitObject



54
55
56
57
58
59
60
61
62
# File 'lib/async/container/forked.rb', line 54

def wait
	return if @finished
	
	@pids.each do |pid|
		::Process.wait(pid)
	end

	@finished = true
end