Class: Async::Container::Forked
- Inherits:
-
Object
- Object
- Async::Container::Forked
- Defined in:
- lib/async/container/forked.rb
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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/async/container/forked.rb', line 29 def initialize(concurrency: 1, name: nil, &block) @pids = concurrency.times.collect do fork do Process.setproctitle(name) if name begin Async::Reactor.run(&block) rescue Interrupt # Exit cleanly. end end end @finished = false end |
Instance Method Details
#stop(signal = :TERM) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/async/container/forked.rb', line 55 def stop(signal = :TERM) @pids.each do |pid| ::Process.kill(signal, pid) rescue nil end wait end |
#wait ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/async/container/forked.rb', line 45 def wait return if @finished @pids.each do |pid| ::Process.wait(pid) end @finished = true end |