Class: Async::Container::Forked
- Inherits:
-
Object
- Object
- Async::Container::Forked
- Defined in:
- lib/async/container/forked.rb
Defined Under Namespace
Classes: Instance
Instance Method Summary collapse
-
#initialize(concurrency: 1, name: nil, &block) ⇒ Forked
constructor
A new instance of Forked.
- #stop(signal = :TERM) ⇒ Object
- #wait ⇒ Object
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 |
#wait ⇒ Object
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 |