Class: Async::Container::Forked

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Forked.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/async/container/forked.rb', line 28

def initialize(concurrency: 1, &block)
  @pids = concurrency.times.collect do
    fork do
      begin
        Async::Reactor.run(&block)
      rescue Interrupt
        # Exit cleanly.
      end
    end
  end
end

Instance Method Details

#stopObject



40
41
42
43
44
45
# File 'lib/async/container/forked.rb', line 40

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