Class: Assistor::AssistantGroup
- Inherits:
-
Object
- Object
- Assistor::AssistantGroup
- Defined in:
- lib/assistor/assistant_group.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #add(assistant) ⇒ Object
- #decrease ⇒ Object
- #filled? ⇒ Boolean
- #flush ⇒ Object
- #increase ⇒ Object
-
#initialize(size) ⇒ AssistantGroup
constructor
A new instance of AssistantGroup.
- #stop ⇒ Object
- #wait ⇒ Object
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
#size ⇒ Object (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 |
#decrease ⇒ Object
46 47 48 |
# File 'lib/assistor/assistant_group.rb', line 46 def decrease @size -= 1 if @size > 0 end |
#filled? ⇒ Boolean
18 19 20 |
# File 'lib/assistor/assistant_group.rb', line 18 def filled? @assistants.size >= size end |
#flush ⇒ Object
14 15 16 |
# File 'lib/assistor/assistant_group.rb', line 14 def flush @assistants.delete_if { |assistant| !assistant.assists? } end |
#increase ⇒ Object
42 43 44 |
# File 'lib/assistor/assistant_group.rb', line 42 def increase @size += 1 end |
#stop ⇒ Object
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 |
#wait ⇒ Object
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 |