Class: Loompa::Children

Inherits:
Array
  • Object
show all
Defined in:
lib/loompa.rb

Instance Method Summary collapse

Instance Method Details

#activeObject



33
34
35
# File 'lib/loompa.rb', line 33

def active()
  self.map{|c| c.active? ? c : nil}.compact
end

#by_fd(fd) ⇒ Object



41
42
43
44
45
46
# File 'lib/loompa.rb', line 41

def by_fd(fd)
  self.each do |c|
    return c if c.from == fd
  end
  nil
end

#cleanupObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/loompa.rb', line 48

def cleanup()
  new = Children.new
  self.each do |c|
    begin
      if Process.waitpid(c.pid, Process::WNOHANG) then
        #Loompa.logger.debug "p: catch exited child #{c.pid}"
        c.exit
      else
        new << c
      end
    rescue Errno::ECHILD
    end
  end
  self.replace new
end

#fdsObject



25
26
27
# File 'lib/loompa.rb', line 25

def fds()
  self.map{|c| c.active? ? c.from : nil}.compact.flatten
end

#idleObject



37
38
39
# File 'lib/loompa.rb', line 37

def idle()
  self.map{|c| c.idle? ? c :  nil}.compact
end

#pidsObject



29
30
31
# File 'lib/loompa.rb', line 29

def pids()
  self.map{|c| c.pid}
end