Class: Assistor::AssistantGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/assistor/assistant_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ AssistantGroup

Returns a new instance of AssistantGroup.



5
6
7
8
# File 'lib/assistor/assistant_group.rb', line 5

def initialize(size)
  @size = size
  @assistants = []
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/assistor/assistant_group.rb', line 3

def size
  @size
end

Instance Method Details

#add(assistant) ⇒ Object



10
11
12
# File 'lib/assistor/assistant_group.rb', line 10

def add(assistant)
  @assistants << assistant
end

#decreaseObject



46
47
48
# File 'lib/assistor/assistant_group.rb', line 46

def decrease
  @size -= 1 if @size > 0
end

#filled?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/assistor/assistant_group.rb', line 18

def filled?
  @assistants.size >= size
end

#flushObject



14
15
16
# File 'lib/assistor/assistant_group.rb', line 14

def flush
  @assistants.delete_if { |assistant| !assistant.assists? }
end

#increaseObject



42
43
44
# File 'lib/assistor/assistant_group.rb', line 42

def increase
  @size += 1
end

#stopObject



32
33
34
35
36
37
38
39
40
# File 'lib/assistor/assistant_group.rb', line 32

def stop
  @assistants.each do |assistant|
    begin
      Process.kill(:INT, assistant.pid)
    rescue Errno::ESRCH
      next
    end
  end
end

#waitObject



22
23
24
25
26
27
28
29
30
# File 'lib/assistor/assistant_group.rb', line 22

def wait
  @assistants.each do |assistant|
    begin
      Process.wait(assistant.pid)
    rescue Errno::ECHILD
      next
    end
  end
end